3 ms·
That's actually not a Monad :-) To be a monad, return must be a left and right identity: x >>= return = x return x >>= f = f x By having return do th
by Peaker 15y ago
That's actually not a Monad :-)
To be a monad, return must be a left and right identity:
x >>= return = x
return x >>= f = f x
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.
- joebo 15y agoThe 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
- pufuwozu 15y agoBug in the type system. Fixed. Roy could be cached so you might need to force a refresh.