Haskell newbie here. I'm trying to understand this example from Haskell's diagrams
library. Specifically, there's a line like this:
Just t = <thing>
where <thing>
is of type Maybe (Tree a)
I don't understand what this is doing. I understand that we need to get the value out from the Maybe
. I replaced that line of code with
t = fromJust <thing>
and it works the same. Is there any difference between the two lines, and can anyone explain what the first line is doing?
fromJust
is pretty much equivalent to:
fromJust :: Maybe a -> a
fromJust (Just t) = t
Note that it’s the same pattern match! If you’re sure that your Maybe
going to be a Just
and not a Nothing
, you can use fromJust
to get its value without pattern matching, but matching is cleaner in most cases, so you don’t need it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With