-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gabi Volpe
committed
Aug 23, 2016
1 parent
50a8a84
commit 0cc9dbd
Showing
1 changed file
with
14 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Control.Monad.Error | ||
|
||
-- definition of the error monad on top of Either | ||
-- instance (Error e) => Monad (Either e) where | ||
-- return x = Right x | ||
-- Right x >>= f = f x | ||
-- Left err >>= f = Left err | ||
-- fail msg = Left (strMsg msg) -- the strMsg function is defined in the Error class | ||
|
||
a1 = Left "boom" >>= \x -> return (x+1) | ||
a2 = Right 100 >>= \x -> Left "no way!" | ||
|
||
-- very important to define the type at the end!!! | ||
b1 = Right 3 >>= \x -> return (x + 100) :: Either String Int |