[mercury-users] More on monads

Fergus Henderson fjh at cs.mu.OZ.AU
Sun Sep 13 05:40:46 AEST 1998


On 12-Sep-1998, Ralph Becket <rwab1 at cam.sri.com> wrote:
> BUT, the point of this note re: Mercury is that, while I believe the
> compiler can unpack all the higher order stuff and simplify 90% of all
> the unused machinery away from the computation, it seems to me that
> there is a lot of unpacking of dead monad objects only to be followed
> by direct repackaging with a new `value' - this isn't going to be
> terribly efficient without compile-time garbage collection.  Am I
> right about this?

If the monad type has only one functor with only one argument, e.g.

	:- type monad(T) ---> mk_monad(whatever(T)).

then the mk_monad/1 constructor is like a `newtype' constructor in Haskell --
it will get optimized away entirely.

But otherwise, e.g. for the maybe(T) monad, you are right that
compile-time garbage collection is needed for maximal efficiency.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.



More information about the users mailing list