user6023611
user6023611

Reputation:

Why this code return Nothing instead of throwing exception

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

Upvotes: 2

Views: 97

Answers (1)

Will Sewell
Will Sewell

Reputation: 2643

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

Upvotes: 10

Related Questions