The option monad example might be closer. I'm having trouble figuring out how to get the value out of it though
data Option a =
Some a | None
let optionMonad = {
return: fn x =
Some x
bind: fn x f = match x
case (Some a) = f a
case None = None
}
let m = (do optionMonad
bind x = Some 1
let y = 2
bind z = Some 3
return x + y + z
)
match m
case (Some x) = console.log x
shows an error Error: Type error: Native is not Option 'dwk
Comments
That's actually not a Monad :-)
To be a monad, return must be a left and right identity:
By having return do things other than wrapping the value, the monad laws are broken.Similarly, bind cannot have such effects, it would break its associativity.
The option monad example might be closer. I'm having trouble figuring out how to get the value out of it though
shows an error Error: Type error: Native is not Option 'dwkBug in the type system. Fixed. Roy could be cached so you might need to force a refresh.