[Haskell-cafe] Newbie Q: composeMaybe :: (a -> Maybe b) -> (b ->
Maybe c) -> (a -> Maybe c)
Dmitri O.Kondratiev
dokondr at gmail.com
Wed Nov 8 09:52:22 EST 2006
I am trying to solve a problem from "The Craft of Functional Programming" book:
14.38 ... define the function:
data Maybe a = Nothing | Just a
composeMaybe :: (a -> Maybe b) -> (b -> Maybe c) -> (a -> Maybe c)
using functions:
squashMaybe :: Maybe (Maybe a) -> Maybe a
squashMaybe (Just (Just x)) = Just x
squashMaybe _ = Nothing
mapMaybe :: (a -> b) -> Maybe a -> Maybe b
mapMaybe f Nothing = Nothing
mapMaybe f (Just x) = Just (f x)
As a first step to the solution I defined auxilary function:
f1 f g x = mapMaybe f (g x)
GHCi gives the following type for this function:
f1 :: (a -> b) -> (t -> Maybe a) -> t -> Maybe b
^^^
Q: I don't quite understand this signature. I would expect this
instead (by mapMaybe definition):
f1 :: (a -> b) -> (t -> Maybe a) -> Maybe b
>From where does the second 't' come from? What are the arguments and
what f1 returns in this case?
More information about the Haskell-Cafe
mailing list