So I whipped up a custom error monad and I was wondering how I would go about proving a few monad laws for it. If anyone is willing to take the time to help me out it would be much appreciated. Thanks!
And here's my code:
data Error a = Ok a | Error String
instance Monad Error where
return = Ok
(>>=) = bindError
instance Show a => Show (Error a) where
show = showError
showError :: Show a => Error a -> String
showError x =
case x of
(Ok v) -> show v
(Error msg) -> show msg
bindError :: Error a -> (a -> Error b) -> Error b
bindError x f = case x of
(Ok v) -> f v
(Error msg) -> (Error msg)