Can you prove that if return a = return b
then a=b
? When I use =
, I mean in the laws and proofs sense, not the Eq
class sense.
Every monad that I know seems to satisfy this, and I can't think of a valid monad that wouldn't (Const a
is a functor and applicative, but not a monad.)
a == b is a expression which return true of false, a bool type, as the return type is int, the evaluation value will be converted implicitly to int before the calling is finished.
You cannot conditionally return from the middle of an expression, because return is a statement, you have to return the whole expression.
In your case, it appears that the statements are taken from the body of a function returning an int (or a related type convertible from int ). So, return 2 simply returns the value 2.
The correct way to indicate that a function does not return a value is to use the return type "void". ( This is a way of explicitly saying that the function returns nothing. ) If no return type is given, the compiler will normally assume the function returns an int.
No. Consider the trivial monad:
data Trivial a = Cow instance Monad Trivial where _ >>= _ = Cow return _ = Cow
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With