Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/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. questions on evaluation. (Peter McIlroy) 2. haskell platform (DJ) 3. Re: haskell platform (Michael Litchard) 4. Re: haskell platform (DJ) 5. Re: questions on evaluation. (Rein Henrichs) 6. Re: questions on evaluation. (Rein Henrichs) ---------------------------------------------------------------------- Message: 1 Date: Mon, 11 Jan 2016 15:18:05 -0800 From: Peter McIlroy <pmcil...@gmail.com> To: beginners@haskell.org Subject: [Haskell-beginners] questions on evaluation. Message-ID: <CAC7vRc12YOci_NU7OwrUhA6s9U=0ymvwz2cttvqzt-lqn1k...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Fabian, For your problem of bang -> baanngggg You can derive Rein's hairy idiom from a more straightforward technique for getting a recursive definition: First get a basic implementation using ++ and recursion: * add a helper function with any "state variables" as arguments. * Ignore concatenation while thinking about a problem. * Use pattern matching for recursion step. This gives the basic (na?ve) implementation: blowup :: [a] -> [a] blowup x = concat (blowup' 1 x) -- returns (e.g.) ["b", "aa", "nnn", "gggg" ] blowup' a b :: Integer a => a -> [b] -> [[b]] blowup' n (x:xs) = (replicate n x : blowup' n+1 xs) blowup' _ _ = [] -- base case You can distribute concatenation into blowup', to get recursion over concatenation, but this really is going the wrong direction: blowup' n (x:xs) = (replicate n x) ++ (blowup' n+1 xs) blowup' _ _ = [] Instead, derive Rein's hairy-looking version by (as always) ignoring concatenation and replacing the state variable in blowup' with zip or zipWith. observe: > zip [1..] "bang" [(1,'b'),(2,'a'),(3,'n'),(4,'g')] So blowup' n x becomes blowup' x: blowup x = concat (blowup' x) blowup' x = map (\(a,b) replicate a b) zip [1..] x ==> definition of zipWith blowup' x = zipWith replicate [1..] x ==> blowup x = concat (zipWith replicate [1..] x) You can always push concat down into a function by unwrapping it with join, getting a more efficient version that creates the result directly. blowup x = concat (zipWith replicate [1..] x) ==> blowup x = (join . zipWith replicate [1..] ) x ==> blowup = join . zipWith replicate [1..] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160111/9a43daac/attachment-0001.html> ------------------------------ Message: 2 Date: Mon, 11 Jan 2016 18:18:42 -0500 From: DJ <ja...@arqux.com> To: beginners@haskell.org Subject: [Haskell-beginners] haskell platform Message-ID: <56943852.90...@arqux.com> Content-Type: text/plain; charset=utf-8; format=flowed Getting back to Haskell after giving up three years ago. I am running Linux Mint 17.1. Why is the Haskell Platform for linux (or my distro anyway) stuck at 2013? I see that ghc is several versions newer than what comes with Haskell Platform. That seems like a rather severe lag. Why is that? Does it matter? Best, - Jake - ------------------------------ Message: 3 Date: Mon, 11 Jan 2016 15:31:20 -0800 From: Michael Litchard <mich...@schmong.org> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] haskell platform Message-ID: <CAEzeKYosLTwp7h=y=tGjGrny0_EJ=85hbjjrjgfnp_sbzek...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Welcome Back! Word on the street is to not use Haskell Platform. Make your life easier by using stack. https://github.com/commercialhaskell/stack/blob/master/doc/GUIDE.md On Mon, Jan 11, 2016 at 3:18 PM, DJ <ja...@arqux.com> wrote: > Getting back to Haskell after giving up three years ago. > > I am running Linux Mint 17.1. > > Why is the Haskell Platform for linux (or my distro anyway) stuck at 2013? > I see that ghc is several versions newer than what comes with Haskell > Platform. That seems like a rather severe lag. > > Why is that? Does it matter? > > Best, > > - Jake - > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160111/d8d8a193/attachment-0001.html> ------------------------------ Message: 4 Date: Mon, 11 Jan 2016 18:43:57 -0500 From: DJ <ja...@arqux.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] haskell platform Message-ID: <56943e3d.7000...@arqux.com> Content-Type: text/plain; charset=windows-1252; format=flowed On 16-01-11 06:31 PM, Michael Litchard wrote: > Welcome Back! > > Word on the street is to not use Haskell Platform. Make your life > easier by using stack. > https://github.com/commercialhaskell/stack/blob/master/doc/GUIDE.md > Ah, cool thanks. I'll check it out. An acquaintance mentioned something about this to me a few days ago, but I didn't know what he was talking about so it didn't register. Best, - Jake - ------------------------------ Message: 5 Date: Tue, 12 Jan 2016 00:10:51 +0000 From: Rein Henrichs <rein.henri...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] questions on evaluation. Message-ID: <cajp6g8wu6kcvhm_jo+gfzu+-wtrpwlch_38eqbzyx4mowy2...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" (blowup' n+1 xs) should be (blowup' (n+1) xs) but otherwise this is spot on. On Mon, Jan 11, 2016 at 3:18 PM Peter McIlroy <pmcil...@gmail.com> wrote: > > Fabian, > > For your problem of bang -> baanngggg > You can derive Rein's hairy idiom from a more straightforward technique > for getting a recursive definition: > > First get a basic implementation using ++ and recursion: > > * add a helper function with any "state variables" as arguments. > * Ignore concatenation while thinking about a problem. > * Use pattern matching for recursion step. > > This gives the basic (na?ve) implementation: > > blowup :: [a] -> [a] > blowup x = concat (blowup' 1 x) > > -- returns (e.g.) ["b", "aa", "nnn", "gggg" ] > blowup' a b :: Integer a => a -> [b] -> [[b]] > blowup' n (x:xs) = (replicate n x : blowup' n+1 xs) > blowup' _ _ = [] -- base case > > You can distribute concatenation into blowup', to get recursion over > concatenation, but this really is going the wrong direction: > > blowup' n (x:xs) = (replicate n x) ++ (blowup' n+1 xs) > blowup' _ _ = [] > > Instead, derive Rein's hairy-looking version by (as always) ignoring > concatenation and replacing the state variable in blowup' with zip or > zipWith. > observe: > > zip [1..] "bang" > [(1,'b'),(2,'a'),(3,'n'),(4,'g')] > > So blowup' n x becomes blowup' x: > blowup x = concat (blowup' x) > > blowup' x = map (\(a,b) replicate a b) zip [1..] x > ==> definition of zipWith > blowup' x = zipWith replicate [1..] x > ==> > blowup x = concat (zipWith replicate [1..] x) > > You can always push concat down into a function by unwrapping it with > join, getting a more efficient version that creates the result directly. > > blowup x = concat (zipWith replicate [1..] x) > ==> > blowup x = (join . zipWith replicate [1..] ) x > ==> > blowup = join . zipWith replicate [1..] > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160112/0f3d33df/attachment-0001.html> ------------------------------ Message: 6 Date: Tue, 12 Jan 2016 00:11:28 +0000 From: Rein Henrichs <rein.henri...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] questions on evaluation. Message-ID: <cajp6g8x5aiyooczsrzz12b2gd2mcnn3qzuy8soajiutyanv...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" And really, I should have used concat instead of join there. On Mon, Jan 11, 2016 at 4:10 PM Rein Henrichs <rein.henri...@gmail.com> wrote: > (blowup' n+1 xs) should be (blowup' (n+1) xs) but otherwise this is spot > on. > > On Mon, Jan 11, 2016 at 3:18 PM Peter McIlroy <pmcil...@gmail.com> wrote: > >> >> Fabian, >> >> For your problem of bang -> baanngggg >> You can derive Rein's hairy idiom from a more straightforward technique >> for getting a recursive definition: >> >> First get a basic implementation using ++ and recursion: >> >> * add a helper function with any "state variables" as arguments. >> * Ignore concatenation while thinking about a problem. >> * Use pattern matching for recursion step. >> >> This gives the basic (na?ve) implementation: >> >> blowup :: [a] -> [a] >> blowup x = concat (blowup' 1 x) >> >> -- returns (e.g.) ["b", "aa", "nnn", "gggg" ] >> blowup' a b :: Integer a => a -> [b] -> [[b]] >> blowup' n (x:xs) = (replicate n x : blowup' n+1 xs) >> blowup' _ _ = [] -- base case >> >> You can distribute concatenation into blowup', to get recursion over >> concatenation, but this really is going the wrong direction: >> >> blowup' n (x:xs) = (replicate n x) ++ (blowup' n+1 xs) >> blowup' _ _ = [] >> >> Instead, derive Rein's hairy-looking version by (as always) ignoring >> concatenation and replacing the state variable in blowup' with zip or >> zipWith. >> observe: >> > zip [1..] "bang" >> [(1,'b'),(2,'a'),(3,'n'),(4,'g')] >> >> So blowup' n x becomes blowup' x: >> blowup x = concat (blowup' x) >> >> blowup' x = map (\(a,b) replicate a b) zip [1..] x >> ==> definition of zipWith >> blowup' x = zipWith replicate [1..] x >> ==> >> blowup x = concat (zipWith replicate [1..] x) >> >> You can always push concat down into a function by unwrapping it with >> join, getting a more efficient version that creates the result directly. >> >> blowup x = concat (zipWith replicate [1..] x) >> ==> >> blowup x = (join . zipWith replicate [1..] ) x >> ==> >> blowup = join . zipWith replicate [1..] >> _______________________________________________ >> Beginners mailing list >> Beginners@haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160112/6fb28759/attachment.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 91, Issue 18 *****************************************