Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why this code return Nothing instead of throwing exception

Tags:

haskell

monads

Could you explain me why following code returns Nothing insteaf od exception "zero" ?

Just 0 >>= (\ x -> if (x == 0) then fail "zero" else Just (x + 1) )

1 Answers

Because you are using the Maybe instance of Monad. This instance defines fail as Nothing.

like image 67
Will Sewell Avatar answered Jul 28 '26 12:07

Will Sewell