Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Environment to map values to var names in intepreter
- Type Env = [(String, Integer)]
- -- Some different type of error (types doesn't matter)
- data SomeError = A String' | B String''
- -- Test monad :
- -- The test monad does some computation in input Env.
- -- Returns either SomeError, or a result of type a.
- -- Side effect in form of output is added to [String]
- newtype Test a = Test {runTest :: Env -> (Either SomeError a, [String]) }
- instance Monad Test where
- return a = Test $ const (Right a, [])
- m >>= f = Test $ \e -> case runTest m e of
- (Left a, x) -> (Left a, x)
- (Right a, s) -> case runTest (f a) e of
- (Left a,x) -> (Left a,x)
- (Right a', s') -> (Right a', s++s')
- -- Monadic doesnt work
- -- m >>= f = Test $ \e ->
- -- runTest m e >>= \t ->
- -- runTest (f (first t)) >>= \t' ->
- -- return t'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement