[Haskell-cafe] Re: Can we come out of a monad?
Dan Doel
dan.doel at gmail.com
Sat Jul 31 09:58:20 EDT 2010
On Saturday 31 July 2010 8:13:37 am Ertugrul Soeylemez wrote:
> I agree to some extent, but only to some. Mostly the problem of people
> is that they are trying to understand "monads" as opposed to specific
> instances. It's better to learn "the IO monad", "state monads", "the
> list monad", "the Maybe monad", "the Parser monad", etc.
I think there are 'easy' answers to "what are monads," too, at least in the
way they tend to appear in Haskell. But, the easiness may well depend on
having background that isn't common in computer programming.
Some of it is, though. "Embedded domain-specific language" is a buzz phrase
these days, so it's probably safe to assume most folks are familiar with the
idea. From that starting point, one might ask how to approach EDSLs from a
more mathematical perspective, and making use of the type system. We might be
led to the following:
1) We want to distinguish 'programs written in the EDSL' via types somehow. It
may not make sense to use EDSL operations just anywhere in the overall
program.
2) Algebra looks promising for talking about languages. Our DSLs will probably
have some base operations, which we'll combine to make our programs. So, our
EDSL type above should probably be related to algebraic theories somehow.
Once we've decided on the above, well, monads are a way in category theory of
talking about algebraic theories. So it stands to reason that a lot of the
EDSLs we're interested in will be monads. And so, by talking about monads in
general, we can construct operations that make sense in and on arbitrary EDSLs
(like, say, sequence = stick together several expressions).
And that covers a lot of what monads are used for in Haskell.
'Maybe a' designates expressions in a language with failure
'Either e a' designates expressions with a throw operation
'State s a' allows get and put
'IO a' has most of the features in imperative languages.
etc.
So the 'easy' answer is that (embedded) languages tend to be algebraic
theories, and monads are a way of talking about those. Of course, that general
answer may still be pretty meaningless if you don't know what algebraic
theories are, so it's still probably good to look at specific monads.
-- Dan
More information about the Haskell-Cafe
mailing list