News for hackers. Stuff that matters.
Re:Roll your own minilanguages with mini-interpreters (1989) by mjburgess on Tuesday July 06, 2021 @06:27AM (#27746402)
I think Haskell's return-type polymorphism makes this much easier.

In other languages, a monadic structure is at least general.

A "monad" is just a type with a sequence operation. The heart of it is just that we aim to do "1 then 2 then 3", etc.

This only becomes something worth talking about when not using the semi-colon to sequence, as we then need to use function application (ie., passing arguments).

The benefit of using a function to sequence operations is that we can just "make it the semicolon", ie., and do nothing extra. *Or* we can add extra functionality, "sequence and ...".

In the case of free monads (I just skim read the article), it appears this "extra" is just a "package" operation. So rather than sequence to execute, we (recursively) wrap in a container.

This recursive container is then an abstract syntax tree, and we can define an interpreter separately.

This I think is very straightforward, and really just confused by terminology. We are just making a AST constructor from a linear sequence of operations.

Re:Roll your own minilanguages with mini-interpreters (1989) by eru on Tuesday July 13, 2021 @02:05AM (#27818020)
> A "monad" is just a type with a sequence operation. The heart of it is just that we aim to do "1 then 2 then 3", etc.

Isn't that an Applicative Functor? Monads also have join / bind.

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.