<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>In this case, I think the straightforward answer is that <tt>result</tt>
is clearly not a monad, just on the basis of its kind! However,
for any fixed <tt>x</tt>, <tt>fn a => result a x</tt> can be
a monad. I suggest reformulating your last definition to be
polymorphic in that way. Probably everything resolves most nicely
if you swap the order of arguments to <tt>result</tt>.<br>
</p>
<div class="moz-cite-prefix">On 2/6/20 1:34 PM, Urs Wegmann wrote:<br>
</div>
<blockquote type="cite"
cite="mid:01bf01d5dd1c$0ad54730$207fd590$@wegmann-informatik.ch">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US">I try to create a monad:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">datatype result a x =<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> Ok of a<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">| Err of x<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">fun mreturn [a] [x] (r :
a) : result a x = Ok r<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">fun mbind [a] [b] [x] (r
: result a x) (f : a -> result b x) : result b x =<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> case r of<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> Ok r => f r<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> | Err x => Err x<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">val result_monad =
mkMonad<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> {<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> Return = @@mreturn,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> Bind = @@mbind<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> }<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">I think the error
message tries to tell me that x is not defined enough. Is
there a way to fix this? When I remove x from result, it
compiles.<o:p></o:p></span></p>
</div>
</blockquote>
</body>
</html>