[Haskell-beginners] Understanding the type signature of flip$id
Jeff Lasslett
jeff.lasslett at gmail.com
Wed Mar 2 00:43:23 CET 2011
Greetings,
I have been reading about how to use system.console.getOpt,
specifically "Interpreting flags as transformations of an options
record" which can be found at
http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-Console-GetOpt.html#4
Line 3 of
compilerOpts argv =
case getOpt Permute options argv of
(o,n,[] ) -> return (foldl (flip id) defaultOptions o, n)
(_,_,errs) -> ioError (userError (concat errs ++ usageInfo
header options))
where header = "Usage: ic [OPTION...] files..."
uses (flip id) to resolve a list of functions down to a single record.
Looking at the type of flip$id I can see why it works in this context.
I just don't understand how passing id to flip results in the
following type signature:
Prelude> :t flip$id
flip$id :: b -> (b -> c) -> c
I do understand what flip has done to map here:-
Prelude> :t flip$map
flip$map :: [a] -> (a -> b) -> [b]
map take a function and a list and produces a new list. If map is
passed to flip the result is a function that takes a list, then a
function and results in a new list.
How do we go from flip having this signature:
Prelude> :t flip
flip :: (a -> b -> c) -> b -> a -> c
Prelude>
and id having
Prelude> :t id
id :: a -> a
Prelude>
to flip$id looking like flip$id :: b -> (b -> c) -> c ???
Thanks,
Jeff
More information about the Beginners
mailing list