On Fri, 22 Apr 2011, Christopher Done wrote:
Use of Fantom's save invoke and Maybe are more or less the same.
-- Hard way
email = if userList /= Nothing
then let user = findUser "bob" (fromJust userList)
in if user /= Nothing
then getEmail (fromJust user)
else Nothing
else Nothing
In idiomatic Haskell you would write
case userList of
Nothing -> Nothing
Just plainUserList =
let user = findUser "bob" plainUserList
...
since (userList /= Nothing) requires an Eq instance without need and it
requires fromJust. Or was there an educational purpose to write it with
(/= Nothing) ?
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe