Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Understanding the type signature of flip$id (Jeff Lasslett) 2. Re: Understanding the type signature of flip$id (Daniel Fischer) 3. Re: Understanding the type signature of flip$id (Jeff Lasslett) 4. Re: Understanding the type signature of flip$id (Christian Maeder) ---------------------------------------------------------------------- Message: 1 Date: Wed, 2 Mar 2011 10:43:23 +1100 From: Jeff Lasslett <jeff.lassl...@gmail.com> Subject: [Haskell-beginners] Understanding the type signature of flip$id To: Beginners@haskell.org Message-ID: <aanlktinn0dwjhdnan_t6npxe-2bf3y_k49yhmqqsp...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 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 ------------------------------ Message: 2 Date: Wed, 2 Mar 2011 01:23:40 +0100 From: Daniel Fischer <daniel.is.fisc...@googlemail.com> Subject: Re: [Haskell-beginners] Understanding the type signature of flip$id To: beginners@haskell.org Message-ID: <201103020123.40334.daniel.is.fisc...@googlemail.com> Content-Type: Text/Plain; charset="iso-8859-1" On Wednesday 02 March 2011 00:43:23, Jeff Lasslett wrote: > 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 The point is that the type of id has to be unified with the type of flip's (first) argument. flip :: (a -> b -> c) -> (b -> a -> c) id :: t -> t So we have to unify (a -> b -> c) and (t -> t). Fully parenthesized, a -> b -> c is a -> (b -> c). Now unification yields t = a -- id's arg must have the same type as the flip's argument's arg and t = (b -> c) -- id's result must have the same result as flip's argument's result >From that follows a = (b -> c) and *id can be passed to flip only at a more restricted type than id's most general type, namely at the type id :: (b -> c) -> (b -> c)* So, flip (id :: (b -> c) -> b -> c) :: b -> (b -> c) -> c ------------------------------ Message: 3 Date: Wed, 2 Mar 2011 16:33:17 +1100 From: Jeff Lasslett <jeff.lassl...@gmail.com> Subject: Re: [Haskell-beginners] Understanding the type signature of flip$id To: Beginners@haskell.org Cc: Daniel Fischer <daniel.is.fisc...@googlemail.com> Message-ID: <aanlktikw2ghewpvhmjwjy-fdo8uywtfqjzs1v+qq5...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Thanks Daniel, I think I follow what you've written. (b -> c) -> (b -> c) is the same as (b -> c) -> b > c and when that is flipped: b -> (b- > c) -> c Is that right? Thanks, Jeff On 2 March 2011 11:23, Daniel Fischer <daniel.is.fisc...@googlemail.com> wrote: > On Wednesday 02 March 2011 00:43:23, Jeff Lasslett wrote: >> ?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 > > The point is that the type of id has to be unified with the type of flip's > (first) argument. > > flip :: (a -> b -> c) -> (b -> a -> c) > id :: t -> t > > So we have to unify (a -> b -> c) and (t -> t). Fully parenthesized, > a -> b -> c is a -> (b -> c). Now unification yields > > t = a > -- id's arg must have the same type as the flip's argument's arg > > and > > t = (b -> c) > -- id's result must have the same result as flip's argument's result > > From that follows a = (b -> c) and *id can be passed to flip only at a more > restricted type than id's most general type, namely at the type > id :: (b -> c) -> (b -> c)* > > So, > > flip (id :: (b -> c) -> b -> c) :: b -> (b -> c) -> c > ------------------------------ Message: 4 Date: Wed, 02 Mar 2011 08:51:43 +0100 From: Christian Maeder <christian.mae...@dfki.de> Subject: Re: [Haskell-beginners] Understanding the type signature of flip$id To: Jeff Lasslett <jeff.lassl...@gmail.com> Cc: Beginners@haskell.org, Daniel Fischer <daniel.is.fisc...@googlemail.com> Message-ID: <4d6df70f.2010...@dfki.de> Content-Type: text/plain; charset=ISO-8859-1 Maybe "flip ($)" is clearer? ($) is identity over function types. If you have the (first) argument you could use a section like "($ a)" and avoid flip. C. Am 02.03.2011 06:33, schrieb Jeff Lasslett: > Thanks Daniel, > > I think I follow what you've written. > > (b -> c) -> (b -> c) is the same as (b -> c) -> b > c > > and when that is flipped: b -> (b- > c) -> c > > Is that right? > > Thanks, > Jeff > > > > On 2 March 2011 11:23, Daniel Fischer <daniel.is.fisc...@googlemail.com> > wrote: >> On Wednesday 02 March 2011 00:43:23, Jeff Lasslett wrote: >>> 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 >> >> The point is that the type of id has to be unified with the type of flip's >> (first) argument. >> >> flip :: (a -> b -> c) -> (b -> a -> c) >> id :: t -> t >> >> So we have to unify (a -> b -> c) and (t -> t). Fully parenthesized, >> a -> b -> c is a -> (b -> c). Now unification yields >> >> t = a >> -- id's arg must have the same type as the flip's argument's arg >> >> and >> >> t = (b -> c) >> -- id's result must have the same result as flip's argument's result >> >> From that follows a = (b -> c) and *id can be passed to flip only at a more >> restricted type than id's most general type, namely at the type >> id :: (b -> c) -> (b -> c)* >> >> So, >> >> flip (id :: (b -> c) -> b -> c) :: b -> (b -> c) -> c >> > ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 33, Issue 1 ****************************************