Monad Type Class in ATS

Run Settings
LanguageATS
Language Version
Run Command
#include "share/atspre_staload.hats" datatype maybe (a:t@ype) = | Nothing (a) of () | Just (a) of a sortdef _tycon = t@ype -> type extern fun {m:_tycon} {a:t@ype} monad$pure (a): m(a) extern fun {m:_tycon} {a,b:t@ype} monad$bind (m(a), a -<cloref1> m(b)): m(b) implement (a:t@ype) monad$pure<maybe><a> (x) = Just (x) implement (a,b:t@ype) monad$bind<maybe><a,b> (x, f) = case+ x of | Just x => f x | Nothing () => Nothing () infixl >>= macdef >>= (x, f) = monad$bind (,(x), ,(f)) implement main0 () = let val x = monad$pure<maybe><int> 10 val n = x >>= (lam x => Just (x+32)) >>= (lam y => let val _ = print_int y in Just " is the answer." end) >>= (lam z => let val _ = print_string z in Nothing {int} () end) : maybe int in end
Editor Settings
Theme
Key bindings
Full width
Lines