<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffee" text="#000000">
Vesa Karvonen wrote:<br>
<blockquote
cite="mid:9e43b9a0704050028tef764e1p2398534e839d8810@mail.gmail.com"
type="cite">BTW, while trying this I noticed that the subexpression
<br>
<br>
M.>>= (f a, return)
<br>
<br>
should be just
<br>
<br>
f a
<br>
<br>
(IIRC - I don't have the corrected code at this point as I kept
editing...)
<br>
</blockquote>
<br>
Ah, yes, that would be true by the monad laws. <br>
<br>
<blockquote
cite="mid:9e43b9a0704050028tef764e1p2398534e839d8810@mail.gmail.com"
type="cite">I see. However, an alternative to having a parameterized
zero would be to
<br>
simply introduce additional thunking in the monad transformer. Here is
<br>
how it would look like (the following code compiles fine):
<br>
<br>
functor MkErrorMonad (M : MONAD_CORE) :> MONADP_CORE = struct
<br>
type 'a monad = 'a Option.t M.monad Thunk.t
<br>
fun return x () = M.return (SOME x)
<br>
fun zero () = M.return NONE
<br>
fun op <|> (aM, bM) () =
<br>
M.>>= (aM (),
<br>
fn SOME a => M.return (SOME a)
<br>
| NONE => bM ())
<br>
fun op >>= (aM, a2bM) () =
<br>
M.>>= (aM (),
<br>
fn SOME a => a2bM a ()
<br>
| NONE => M.return NONE)
<br>
end
<br>
<br>
So, it seems that it is always possible to work around the value
<br>
restriction in this context (which is when implementing MONADP_CORE).
<br>
<br>
In a sense, even when implementing a monad transformer, you are
<br>
implementing a MONADP from scratch, because you get to decide the
<br>
type of the resulting monad.
<br>
</blockquote>
<br>
Okay, after thinking about your solution some more you are
correct. Because thunks themselves form a monad, it should always be
possible to transform problematic definition into one using thunks.
Clearly I should have spent more time thinking about this first. <br>
<br>
<pre class="moz-signature" cols="72">--
[Geoff Washburn|<a class="moz-txt-link-abbreviated" href="mailto:geoffw@cis.upenn.edu">geoffw@cis.upenn.edu</a>|<a class="moz-txt-link-freetext" href="http://www.cis.upenn.edu/~geoffw/">http://www.cis.upenn.edu/~geoffw/</a>]
</pre>
</body>
</html>