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. map question (Joost Kremers) 2. Re: map question (Daniel Fischer) 3. Re: map question (Brent Yorgey) 4. Re: map question (Joost Kremers) 5. How to import the Data.Char library in Hugs? (Benjamin L.Russell) 6. Re: How to import the Data.Char library in Hugs? (Adrian Neumann) 7. Re: How to import the Data.Char library in Hugs? (Daniel Fischer) 8. Re: map question (Tom Doris) 9. Re: map question (Magnus Therning) 10. Re: map question (Tommy M. McGuire) ---------------------------------------------------------------------- Message: 1 Date: Thu, 17 Sep 2009 13:31:38 +0200 From: Joost Kremers <joostkrem...@fastmail.fm> Subject: [Haskell-beginners] map question To: beginners@haskell.org Message-ID: <20090917113138.gc15...@enterprise.localdomain> Content-Type: text/plain; charset=utf-8 Hi all, I've just started learning Haskell and while experimenting with map a bit, I ran into something I don't understand. The following commands do what I'd expect: Prelude> map (+ 1) [1,2,3,4] [2,3,4,5] Prelude> map (* 2) [1,2,3,4] [2,4,6,8] Prelude> map (/ 2) [1,2,3,4] [0.5,1.0,1.5,2.0] Prelude> map (2 /) [1,2,3,4] [2.0,1.0,0.6666666666666666,0.5] But I can't seem to find a way to get map to substract 1 from all members of the list. The following form is the only one that works, but it doesn't give the result I'd expect: Prelude> map ((-) 1) [1,2,3,4] [0,-1,-2,-3] I know I can use an anonymous function, but I'm just trying to understand the result here... I'd appreciate any hints to help me graps this. TIA Joost -- Joost Kremers, PhD University of Frankfurt Institute for Cognitive Linguistics Grüneburgplatz 1 60629 Frankfurt am Main, Germany ------------------------------ Message: 2 Date: Thu, 17 Sep 2009 13:50:27 +0200 From: Daniel Fischer <daniel.is.fisc...@web.de> Subject: Re: [Haskell-beginners] map question To: beginners@haskell.org Message-ID: <200909171350.27848.daniel.is.fisc...@web.de> Content-Type: text/plain; charset="utf-8" Am Donnerstag 17 September 2009 13:31:38 schrieb Joost Kremers: > Hi all, > > I've just started learning Haskell and while experimenting with map a bit, > I ran into something I don't understand. The following commands do what I'd > expect: > > Prelude> map (+ 1) [1,2,3,4] > [2,3,4,5] > Prelude> map (* 2) [1,2,3,4] > [2,4,6,8] > Prelude> map (/ 2) [1,2,3,4] > [0.5,1.0,1.5,2.0] > Prelude> map (2 /) [1,2,3,4] > [2.0,1.0,0.6666666666666666,0.5] > > But I can't seem to find a way to get map to substract 1 from all members > of the list. The following form is the only one that works, but it doesn't > give the result I'd expect: > > Prelude> map ((-) 1) [1,2,3,4] > [0,-1,-2,-3] > > I know I can use an anonymous function, but I'm just trying to understand > the result here... I'd appreciate any hints to help me graps this. (-) a b = a - b, so (((-) 1) x) = 1 - x and you've mapped (\x -> 1-x) over the list. You want to map (\x -> x-1), which is map (subtract 1) list or map (flip (-) 1) list (or map (+ (-1)) list) > > TIA > > Joost ------------------------------ Message: 3 Date: Thu, 17 Sep 2009 08:01:50 -0400 From: Brent Yorgey <byor...@seas.upenn.edu> Subject: Re: [Haskell-beginners] map question To: beginners@haskell.org Message-ID: <20090917120150.ga20...@seas.upenn.edu> Content-Type: text/plain; charset=us-ascii On Thu, Sep 17, 2009 at 01:31:38PM +0200, Joost Kremers wrote: > > But I can't seem to find a way to get map to substract 1 from all members of > the > list. The following form is the only one that works, but it doesn't give the > result I'd expect: > > Prelude> map ((-) 1) [1,2,3,4] > [0,-1,-2,-3] By the way, the reason map (+1) [1,2,3,4] works but map (-1) [1,2,3,4] doesn't is because of an ugly corner of Haskell syntax: -1 here is parsed as negative one, rather than an operator section with subtraction. The 'subtract' function is provided exactly for this purpose, so that you can write map (subtract 1) [1,2,3,4] instead. -Brent ------------------------------ Message: 4 Date: Thu, 17 Sep 2009 14:01:47 +0200 From: Joost Kremers <joostkrem...@fastmail.fm> Subject: Re: [Haskell-beginners] map question To: beginners@haskell.org Message-ID: <20090917120147.ga29...@enterprise.localdomain> Content-Type: text/plain; charset=utf-8 On Thu, Sep 17, 2009 at 01:50:27PM +0200, Daniel Fischer wrote: > > Prelude> map ((-) 1) [1,2,3,4] > > [0,-1,-2,-3] > > > > I know I can use an anonymous function, but I'm just trying to understand > > the result here... I'd appreciate any hints to help me graps this. > > (-) a b = a - b, so (((-) 1) x) = 1 - x and you've mapped (\x -> 1-x) over > the list. Ah yes... Of course, I didn't realise that wrapping a binary operator in parens turns it into a normal function. And from <http://www.haskell.org/onlinereport/exps.html#sect3.5>, which someone pointed me to off-list, I gather that in (- 1) the minus sign is interpreted as the unary operator, not the binary one. Which means that (- 1) is not a function, which means map will barf. Ok, thanks, all makes sense now! Joost -- Joost Kremers Life has its moments ------------------------------ Message: 5 Date: Thu, 17 Sep 2009 21:41:47 +0900 From: Benjamin L.Russell <dekudekup...@yahoo.com> Subject: [Haskell-beginners] How to import the Data.Char library in Hugs? To: beginners@haskell.org Message-ID: <u6b4b59ablmitohek8um69slr00b4f9...@4ax.com> Content-Type: text/plain; charset=us-ascii My apologies if this is an extremely elementary question, but I am having difficulties in importing the Data.Char library in Hugs. In GHCi, the command "import Data.Char" works correctly, as follows: --8<---------------cut here---------------start------------->8--- GHCi, version 6.10.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Interactive, for Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \____/\/ /_/\____/|_| Type :? for help. Prelude> import Data.Char Prelude Data.Char> --8<---------------cut here---------------end--------------->8--- However, in Hugs, the same command fails with an error, as follows: --8<---------------cut here---------------start------------->8--- __ __ __ __ ____ ___ _________________________________________ || || || || || || ||__ Hugs 98: Based on the Haskell 98 standard ||___|| ||__|| ||__|| __|| Copyright (c) 1994-2005 ||---|| ___|| World Wide Web: http://haskell.org/hugs || || Bugs: http://hackage.haskell.org/trac/hugs || || Version: 20051031 _________________________________________ Haskell 98 mode: Restart with command line option -98 to enable extensions Type :? for help Hugs> import Data.Char ERROR - Syntax error in expression (unexpected keyword "import") Hugs> --8<---------------cut here---------------end--------------->8--- Does anybody know how to import the Data.Char library in Hugs? -- Benjamin L. Russell -- Benjamin L. Russell / DekuDekuplex at Yahoo dot com http://dekudekuplex.wordpress.com/ Translator/Interpreter / Mobile: +011 81 80-3603-6725 "Furuike ya, kawazu tobikomu mizu no oto." -- Matsuo Basho^ ------------------------------ Message: 6 Date: Thu, 17 Sep 2009 15:02:21 +0200 From: Adrian Neumann <aneum...@inf.fu-berlin.de> Subject: Re: [Haskell-beginners] How to import the Data.Char library in Hugs? Cc: beginners@haskell.org Message-ID: <4ab2335d.2030...@inf.fu-berlin.de> Content-Type: text/plain; charset="iso-8859-1" You do > :l Data.Char As far as I know you can't have multiple loaded modules unless you put them in a file and load that. Regards, Adrian Benjamin L.Russell schrieb: > My apologies if this is an extremely elementary question, but I am > having difficulties in importing the Data.Char library in Hugs. > > In GHCi, the command "import Data.Char" works correctly, as follows: > > --8<---------------cut here---------------start------------->8--- > GHCi, version 6.10.3: http://www.haskell.org/ghc/ :? for help > Loading package ghc-prim ... linking ... done. > Loading package integer ... linking ... done. > Loading package base ... linking ... done. > ___ ___ _ > / _ \ /\ /\/ __(_) > / /_\// /_/ / / | | GHC Interactive, for Haskell 98. > / /_\\/ __ / /___| | http://www.haskell.org/ghc/ > \____/\/ /_/\____/|_| Type :? for help. > > Prelude> import Data.Char > Prelude Data.Char> > --8<---------------cut here---------------end--------------->8--- > > However, in Hugs, the same command fails with an error, as follows: > > --8<---------------cut here---------------start------------->8--- > __ __ __ __ ____ ___ _________________________________________ > || || || || || || ||__ Hugs 98: Based on the Haskell 98 standard > ||___|| ||__|| ||__|| __|| Copyright (c) 1994-2005 > ||---|| ___|| World Wide Web: http://haskell.org/hugs > || || Bugs: http://hackage.haskell.org/trac/hugs > || || Version: 20051031 _________________________________________ > > Haskell 98 mode: Restart with command line option -98 to enable > extensions > > Type :? for help > Hugs> import Data.Char > ERROR - Syntax error in expression (unexpected keyword "import") > Hugs> > --8<---------------cut here---------------end--------------->8--- > > Does anybody know how to import the Data.Char library in Hugs? > > -- Benjamin L. Russell -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 251 bytes Desc: OpenPGP digital signature Url : http://www.haskell.org/pipermail/beginners/attachments/20090917/4aa56846/signature-0001.bin ------------------------------ Message: 7 Date: Thu, 17 Sep 2009 15:04:07 +0200 From: Daniel Fischer <daniel.is.fisc...@web.de> Subject: Re: [Haskell-beginners] How to import the Data.Char library in Hugs? To: beginners@haskell.org Message-ID: <200909171504.07566.daniel.is.fisc...@web.de> Content-Type: text/plain; charset="iso-8859-1" Am Donnerstag 17 September 2009 14:41:47 schrieb Benjamin L.Russell: > My apologies if this is an extremely elementary question, but I am > having difficulties in importing the Data.Char library in Hugs. Hugs> :a Data.Char Data.Char> ------------------------------ Message: 8 Date: Thu, 17 Sep 2009 14:06:23 +0100 From: Tom Doris <tomdo...@gmail.com> Subject: Re: [Haskell-beginners] map question To: Joost Kremers <joostkrem...@fastmail.fm> Cc: beginners@haskell.org Message-ID: <19e5d1d00909170606l18ef6ae6n45cd4c2f69532...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" This works: map (+ (-1)) [1,2,3,4] 2009/9/17 Joost Kremers <joostkrem...@fastmail.fm> > Hi all, > > I've just started learning Haskell and while experimenting with map a bit, > I ran > into something I don't understand. The following commands do what I'd > expect: > > Prelude> map (+ 1) [1,2,3,4] > [2,3,4,5] > Prelude> map (* 2) [1,2,3,4] > [2,4,6,8] > Prelude> map (/ 2) [1,2,3,4] > [0.5,1.0,1.5,2.0] > Prelude> map (2 /) [1,2,3,4] > [2.0,1.0,0.6666666666666666,0.5] > > But I can't seem to find a way to get map to substract 1 from all members > of the > list. The following form is the only one that works, but it doesn't give > the > result I'd expect: > > Prelude> map ((-) 1) [1,2,3,4] > [0,-1,-2,-3] > > I know I can use an anonymous function, but I'm just trying to understand > the > result here... I'd appreciate any hints to help me graps this. > > TIA > > Joost > > > -- > Joost Kremers, PhD > University of Frankfurt > Institute for Cognitive Linguistics > Grüneburgplatz 1 > 60629 Frankfurt am Main, Germany > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090917/3d8634f3/attachment-0001.html ------------------------------ Message: 9 Date: Thu, 17 Sep 2009 14:54:19 +0100 From: Magnus Therning <mag...@therning.org> Subject: Re: [Haskell-beginners] map question To: Tom Doris <tomdo...@gmail.com> Cc: beginners@haskell.org Message-ID: <e040b520909170654s1b190e2bi8ff562f06cc82...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Thu, Sep 17, 2009 at 2:06 PM, Tom Doris <tomdo...@gmail.com> wrote: > This works: > > map (+ (-1)) [1,2,3,4] map pred [1..4] /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnusï¼ therningï¼org Jabber: magnusï¼ therningï¼org http://therning.org/magnus identi.ca|twitter: magthe ------------------------------ Message: 10 Date: Thu, 17 Sep 2009 10:05:43 -0500 From: "Tommy M. McGuire" <mcgu...@crsr.net> Subject: Re: [Haskell-beginners] map question To: Magnus Therning <mag...@therning.org> Cc: beginners@haskell.org Message-ID: <4ab25047.4010...@crsr.net> Content-Type: text/plain; charset=UTF-8 Cue The Evolution of a Haskell Programmer: http://www.willamette.edu/~fruehr/haskell/evolution.html :-) Magnus Therning wrote: > On Thu, Sep 17, 2009 at 2:06 PM, Tom Doris <tomdo...@gmail.com> wrote: >> This works: >> >> map (+ (-1)) [1,2,3,4] > > map pred [1..4] > > /M > -- Tommy M. McGuire mcgu...@crsr.net ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 15, Issue 12 *****************************************