Ich möchte Option Monad in SML implementieren, damit ich sie genauso verwenden kann, wie sie in Haskell verwendet werden können. Was ich getan habe, funktioniert nicht.SML-Option Monad (Bind-Operator funktioniert nicht)
infix 1 >>=
signature MONAD =
sig
type 'a m
val return : 'a -> 'a m
val >>= : 'a m * ('a -> 'b m) -> 'b m
end;
structure OptionM : MONAD =
struct
type 'a m = 'a option
val return = SOME
fun x >>= k = Option.mapPartial k x
end;
val x = OptionM.return 3;
x (OptionM.>>=) (fn y => NONE);
Ergebnis:
stdIn:141.1-141.31 Error: operator is not a function [tycon mismatch]
operator: int OptionM.m
in expression:
x OptionM.>>=
Was kann ich tun, um die letzte Zeile der Arbeit zu machen?
Hier ist eine [Lösung] (http://stackoverflow.com/a/ 14129095/2747511) - nur 'open OptionM'. –
Oder 'val op >> = = OptionM. >> ='. –