News for hackers. Stuff that matters.
Re:Roll your own minilanguages with mini-interpreters (1989) by quickthrower2 on Tuesday July 06, 2021 @05:06PM (#27754234)
Yeah for some reason this explanation which should be simple just blows my mind. I’m probably too experienced in imperative languages. It took me a long time to grok plain old monads. And when you get those GHC compiler errors from heavily stacked up types I find it very hard to work out what went wrong. For practical purposes I prefer OO even though it might be more limited in some regards.
Re:Roll your own minilanguages with mini-interpreters (1989) by mjburgess on Thursday July 08, 2021 @09:20AM (#27771591)

    p = newPerson();
    w = walk(p);
    t = talk(p, w);
    s = shout(p, t);

becomes,

    seq(shout, seq(talk, seq(walk, seq(newPerson())))

"infix",

    newPerson() seq
    walk seq
    talk seq
    shout 

The operations `newPerson` and `seq` form a monad.

If you can omit `w =`, `t=`, and `s=` you have an applicative, rather than a monad. Ie., the operations being sequenced are independent.