Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If return a = return b then does a=b?

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.)

like image 806
PyRulez Avatar asked Jan 25 '16 23:01

PyRulez


People also ask

What does a == b return?

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.

Can we use return in conditional statement?

You cannot conditionally return from the middle of an expression, because return is a statement, you have to return the whole expression.

What does return 2 mean?

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.

What will happen when a function returns a value that does not match with the return type of the function?

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.


1 Answers

No. Consider the trivial monad:

data Trivial a = Cow  instance Monad Trivial where   _ >>= _ = Cow   return _ = Cow 
like image 93
Andrej Bauer Avatar answered Sep 29 '22 17:09

Andrej Bauer