My question is simple. Why pattern matching does not throw an exception in Maybe monad. For clarity:
data Task = HTTPTask { getParams :: [B.ByteString], postParams :: [B.ByteString], rawPostData :: B.ByteString } deriving (Show) tryConstuctHTTPTask :: B.ByteString -> Maybe Task tryConstuctHTTPTask str = do case decode str of Left _ -> fail "" Right (Object trie) -> do Object getP <- DT.lookup (pack "getParams") trie Object postP <- DT.lookup (pack "postParams") trie String rawData <- DT.lookup (pack "rawPostData") trie return $ HTTPTask [] [] rawData
Take a look at the tryConstuctHTTPTask function. I think that when the template does not match (for example, "Object getP"), we should get something like "Prelude.Exception", instead we will get "Nothing". I like this behavior, but I donβt understand why.
Thanks.
exception haskell monads
Anton
source share