Dec. 10th, 2012

juan_gandhi: (VP)
1. [livejournal.com profile] sassa_nf noted that in Haskell actually Reader composes with any monad. That's a pleasant surprise; and this happens due to the fact that any monad is strong in Haskell. Yes, with the same arguments as I used before, a composition of Reader with any monad is still a monad.

2. The proof of monadicity of Reader and Maybe (or any other strong monad).
I tried; it is long and boring, and there's nothing unusual there, just apply diagonals and eval, and use Yoneda lemma. No big deal, boring.

3. What is eval actually?
3.1. Formal definition.
eval: A × BA → B

is defined via adjointness of functors X- and -×Y, it comes from idA: A → B.

3.2. Informal definition.
Given (a,f) ∈ A × BA, eval(a,f)=f(a).

4. How does it all look in Java?
Given
interface Maybe<X> {
  X getOrElse(X alt);
  <Y> Maybe<Y> map(Function<X,Y> f);
  <Y> Maybe<Y> flatMap(Function<X,Maybe<Y> f);
}

with two implementation classes, Some and None (having appropriate factories),
and
abstract class Reader<E,X> {
  <X,Y> Reader<E,Y> map(Function<X,Y> f);
  <X,Y> Reader<E,Y> flatMap(Function<X,Reader<E,Y> f);
}

with a factory
  <E,X> Reader<E,X> reader(X x) { return new Reader<E,X){...}; } // constant x

and provided the implementations follows monadic laws,

We can define
class<E,X> PartialReader<E,X> extends Reader<E,Maybe<X>>{
  <X,Y> PartialReader<E,Y> map(Function<X,Y> f) { ... }
  <X,Y> PartialReader<E,Y> flatMap(Function<X,Reader<E,Maybe<Y> f) { ... }
}


and a factory
  <E,X> PartialReader<E,X> pr(X x) { return new PartialReader<E,X){...}; } // constant Some(x)


Now this PartialReader satisfies monadic laws.

I wonder, do I need to define the guts of the methods? I could, no request.

мдв

Dec. 10th, 2012 10:44 pm
juan_gandhi: (VP)
маленький дурацкий вопрос

А что это вообще за херня, это понятие "эмигранской литературы"? Это часом, не совписы выдумали, чтобы самим себе казаться величавыми?

Гоголь, Герцен, Горький, Северянин, Конрад, Турсун-заде, Киплинг, Джойс, Хемингуэй, Искандер, Рытхэу, Тан, Рушди, Эри, Данте... это всё эмигрантские писатели?

Я что хочу сказать - московские писатели-члены должны пойти согласно своему самоназванию в пешее эротическое путешествие. И питерские туда же, и тульские.

Или ты писатель, или ты не писатель. Всё. Панаев и Скабичевский.

И вообще эпоха интернета, всем почти пофиг откуда ты.

В этом смысле подрывная деятельность находящихся за пределами России издателей русскоязычной литературы вызывает у меня глубочайшее уважение.

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

August 2025

S M T W T F S
      12
3456789
10 11 12 13141516
17181920212223
24252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 19th, 2025 03:44 pm
Powered by Dreamwidth Studios