4 ms·
SML is impure. You are arguing for purity, which is a separate issue from support for monads. Saying "SML doesn't really have support for monads because it's im
by rntz 15y ago
SML is impure. You are arguing for purity, which is a separate issue from support for monads. Saying "SML doesn't really have support for monads because it's impure" is confusing an idea (monads) with a particular application of that idea (using special monads like IO to separate pure from side-effectful code).
To be fair, Harper's comment is practically a pretty silly proposition. But the primary technical claim of his post (SML supports monads) is true. This is a common issue with Harper: he rarely says anything factually incorrect, but the moral conclusions he draws are out of proportion with the technical points he makes.
- Peaker 15y agoI never intended to imply that lack of effect segregation imposition means that there can be no Monads in SML, I was just replying to that particular tidbit of his. While there may very well be monads in SML, he still haven't made it clear the Monad abstraction is possible, because he hasn't actually written any code that's generalized to any monad (e.g: Haskell's sequence, liftM2, and so forth).
- loup-vaillant 15y agoThat last part is trivial: Just put those generic function in a functor, that take a Monad module as a parameter. Assuming I got the functor syntax right (unlikely), it should look something like: functor MonadUtils MONAD = struct sequence : 'a MONAD.monad list -> 'a list MONAD.monad (* and so on *) end
- rntz 15y agoClose, but no cigar. functor MonadUtils (M : MONAD) = struct (* type annotations not strictly necessary *) fun sequence (ms : 'a M.monad list) : 'a list M.monad = let fun mcons (elt, rest) = M.bnd elt (fn e => M.bnd rest (fn r => M.ret (e::r))) in foldr mcons (M.ret []) ms end end