lundi 2 mars 2015

Haskell non-exhaustive patterns with matching Either


Vote count:

0




I wish to implement a function eitherMap with following spec:



eitherMap :: (a -> c) -> (b -> d) -> Either a b -> Either c d


which takes in two functions and map one of the function to input.


My current implementation is straight-forward as:



eitherMap fa fb (Left a) = Left (fa a)
eithermap fa fb (Right b) = Right (fb b)


It works fine with some cases but not some others involving list function.



> eitherMap (+2) reverse (Left 3)
Left 5
> eitherMap (+2) reverse (Right [2,3,4])
*** Exception: ...: Non-exhaustive patterns in function eitherMap


Can somebody give me a hint why this is happening? Thanks!



asked 1 min ago

Ray

1,557






Haskell non-exhaustive patterns with matching Either

Aucun commentaire:

Enregistrer un commentaire