[Haskell] Mixing monadic and non-monadic functions

Frederik Eaton frederik at a5.repetae.net
Thu Sep 8 05:21:25 EDT 2005


On Thu, Sep 08, 2005 at 10:35:49AM +0200, Wolfgang Lux wrote:
> Frederik Eaton wrote:
> 
> >I want the type system to be able to do "automatic lifting" of monads,
> >i.e., since [] is a monad, I should be able to write the following:
> >and have it interpreted as "do {a<-[1,2]; b<-[3,4]; return (a+b)}".
> 
> Are you sure that this is the interpretation you have in mind? The
> expression do {a<-[1,2]; b<-[3,4]; return (a+b)} does *not* compute the
> element-wise sum of the two lists, but returns the list [4,5,5,6]. To
> me, this would be a very counter intuitive result for an expression
> [1,2]+[3,4].

Thanks for bringing up a good point. Yes, this is what I have in mind.

As I see it, the monadic interface for lists gives them the semantics
of (multi)sets. Adding two sets could only be interpreted as I have
said.

If you were adding, say, arrays, elementwise, the monad would be more
like a reader monad, which I also gave an example of, with the
parameter being the array index.

Furthermore, it's hard to see how one would elegantly flesh out the
semantics you propose for lists. What if the two lists have different
lengths? Thus I think set semantics is more appropriate for a list
monad.

Frederik

-- 
http://ofb.net/~frederik/


More information about the Haskell mailing list