How to get the value of a Maybe in Haskell
-
31-10-2019 - |
Question
I'm relatively new to Haskell and began to read "Real World Haskell".
I Just stumbled over the type Maybe and have a question about how to receive the actual value from a Just 1
for example.
I have written the following code:
combine a b c = (eliminate a, eliminate b, eliminate c)
where eliminate (Just a) = a
eliminate Nothing = 0
This works fine if I use:
combine (Just 1) Nothing (Just 2)
But if I change, for example, 1 to a String it doesn't work.
I think I know why: because eliminate
has to give back one type, which is, in this case, an Int
. But how can I change eliminate
to deal at least with Strings (or maybe with all kind of types)?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow