[mercury-users] Uniqueness modes etc

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Jan 12 22:10:25 AEDT 2004


On 12-Jan-2004, Dr Mark H Phillips <mark at austrics.com.au> wrote:
> 
> Is there monad support already in Mercury?

No.

Currently Mercury doesn't support constructor classes, which would be
needed to implement a monad type class like Haskell has.  You should be
able to implement particular monads, e.g. the list monad, without much
difficulty, but it's not so easy to abstract over all of them.

Monads are difficult to understand -- witness the long discussion
about monads which is currently running on comp.lang.functional.
This difficulty of understanding in part to historical reasons and in
part to the use of unintuitive nomenclature, but is also to some degree
inherent, because the monad type class is a very abstract, and because
it relies on other complicated constructs like higher-order functions,
continuation passing, and constructor classes.  Furthermore, unless
you use some syntactic sugar, code written using monads is quite ugly.

In many cases, code written without monads can be clearer.  For example,
Mercury's store type, which is Mercury's alternative to Glasgow Haskell's
state monad, is IMHO easier to understand and to use than GHC's state monad.
With GHC's state monad, it is not possible to simply create a state
and then update it -- instead you have to create a computation which
will manipulate a state and then use a higher-order function "runST" to
invoke your computation.  GHC's state monad also relies on first-class
polymorphism, which is a type system extension not present in standard
Haskell or Mercury.

So, even if we did support constructor classes, I'm not sure if I would
want to then provide special syntactic sugar for monads.  Mercury provides
other alternatives for most of the uses of monads, and there would be
little incentive for us to provide special syntactic sugar for something
which would rarely be used.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list