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. Re: making function problem (chapter 6 of Programming in Haskell) (Roelof Wobben) 2. Re: making function problem (chapter 6 of Programming in Haskell) (Daniel Seidel) 3. Re: making function problem (chapter 6 of Programming in Haskell) (Roelof Wobben) 4. Re: making function problem (chapter 6 of Programming in Haskell) (Daniel Seidel) 5. Re: making function problem (chapter 6 of Programming in Haskell) (Roelof Wobben) 6. Re: making function problem (chapter 6 of Programming in Haskell) (Daniel Seidel) 7. What is the use of Data.List.Key merge (informationen) 8. Re: What is the use of Data.List.Key merge (Antoine Latter) 9. Why ShowS? (Christopher Howard) 10. Re: Why ShowS? (Brandon Allbery) ---------------------------------------------------------------------- Message: 1 Date: Tue, 9 Aug 2011 12:16:52 +0000 From: Roelof Wobben <rwob...@hotmail.com> Subject: Re: [Haskell-beginners] making function problem (chapter 6 of Programming in Haskell) To: <beginners@haskell.org> Message-ID: <snt118-w222be1b49a07d09163aba1ae...@phx.gbl> Content-Type: text/plain; charset="iso-8859-1" ---------------------------------------- > Date: Mon, 8 Aug 2011 14:59:39 -0700 > From: kc1...@gmail.com > To: beginners@haskell.org > Subject: Re: [Haskell-beginners] making function problem (chapter 6 of > Programming in Haskell) > > Hint > > positivePower :: Int -> Int -> Int > positivePower x 1 = x > positivePower x y = dododoo positivePower yadayada > > > -- > -- > Regards, > KC > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners oke. I see it I'm going for this : postivePower :: Int -> Int -> Int PostivePower x 1 = 1 because when you multiply something by one is remains the same value. PostivePower x y = x + postivePower x y for example x = 4 y = 3 4 * 3 = 4 + 4 * 2 4 + 4 + 4 * 1 4 + 4 + 4 4 + 8 12 Roelof ------------------------------ Message: 2 Date: Tue, 09 Aug 2011 14:41:13 +0200 From: Daniel Seidel <d...@iai.uni-bonn.de> Subject: Re: [Haskell-beginners] making function problem (chapter 6 of Programming in Haskell) To: Roelof Wobben <rwob...@hotmail.com> Cc: beginners@haskell.org Message-ID: <1312893673.12191.8.ca...@entwood.iai.uni-bonn.de> Content-Type: text/plain Hi Roelof, On Tue, 2011-08-09 at 12:16 +0000, Roelof Wobben wrote: > oke. > > > > I see it > unfortunately its still not true. Your example with the concrete numbers is right, and it captures the scheme well. But try to check your code with it. I'd like to say its typos, but its actually the same typos as you had for the actual main example, calculating the lists. Try to answer the questions I ask below and then use the answers for a correct definition (that is very similar to the recent one). > > > I'm going for this : > > > > postivePower :: Int -> Int -> Int > > PostivePower x 1 = 1 because when you multiply something by one is > remains the same value. Does this really return the value you want? Is 5 * 1 = 1 ? > > PostivePower x y = x + postivePower x y > Do you really want to call positivePower with the same y again, or more concretely: Is 4 * 3 = 4 + (4 * 3)?, or should there be a "2" somewhere? > > > for example > > > > x = 4 > > y = 3 > > > > 4 * 3 = > > 4 + 4 * 2 > > 4 + 4 + 4 * 1 > > 4 + 4 + 4 > > 4 + 8 > > 12 > ------------------------------ Message: 3 Date: Tue, 9 Aug 2011 12:44:06 +0000 From: Roelof Wobben <rwob...@hotmail.com> Subject: Re: [Haskell-beginners] making function problem (chapter 6 of Programming in Haskell) To: <beginners@haskell.org> Message-ID: <snt118-w35e88500fe62225c46d87fae...@phx.gbl> Content-Type: text/plain; charset="iso-8859-1" ---------------------------------------- > Subject: Re: [Haskell-beginners] making function problem (chapter 6 of > Programming in Haskell) > From: d...@iai.uni-bonn.de > To: rwob...@hotmail.com > CC: beginners@haskell.org > Date: Tue, 9 Aug 2011 14:41:13 +0200 > > Hi Roelof, > > On Tue, 2011-08-09 at 12:16 +0000, Roelof Wobben wrote: > > oke. > > > > > > > > I see it > > > unfortunately its still not true. Your example with the concrete numbers > is right, and it captures the scheme well. But try to check your code > with it. I'd like to say its typos, but its actually the same typos as > you had for the actual main example, calculating the lists. > Try to answer the questions I ask below and then use the answers for a > correct definition (that is very similar to the recent one). > > > > > > I'm going for this : > > > > > > > > postivePower :: Int -> Int -> Int > > > > PostivePower x 1 = 1 because when you multiply something by one is > > remains the same value. > Does this really return the value you want? Is 5 * 1 = 1 ? > > > > PostivePower x y = x + postivePower x y > > > Do you really want to call positivePower with the same y again, or more > concretely: Is 4 * 3 = 4 + (4 * 3)?, or should there be a "2" somewhere? > It should be 2 so it would then be postivepower x y = x + postivepower x (y-1) Roelof ------------------------------ Message: 4 Date: Tue, 09 Aug 2011 15:12:56 +0200 From: Daniel Seidel <d...@iai.uni-bonn.de> Subject: Re: [Haskell-beginners] making function problem (chapter 6 of Programming in Haskell) To: Roelof Wobben <rwob...@hotmail.com> Cc: beginners@haskell.org Message-ID: <1312895576.12191.13.ca...@entwood.iai.uni-bonn.de> Content-Type: text/plain On Tue, 2011-08-09 at 12:44 +0000, Roelof Wobben wrote: > > > PostivePower x y = x + postivePower x y > > > > > Do you really want to call positivePower with the same y again, or > more > > concretely: Is 4 * 3 = 4 + (4 * 3)?, or should there be a "2" > somewhere? > > > > > > > It should be 2 so it would then be postivepower x y = x + postivepower > x (y-1) Right! That's it. Now it's hopefully not a problem to write the (^) function with the same scheme. Cheers, Daniel. ------------------------------ Message: 5 Date: Tue, 9 Aug 2011 13:37:22 +0000 From: Roelof Wobben <rwob...@hotmail.com> Subject: Re: [Haskell-beginners] making function problem (chapter 6 of Programming in Haskell) To: <beginners@haskell.org> Message-ID: <snt118-w5162cde0acd301212f0d33ae...@phx.gbl> Content-Type: text/plain; charset="iso-8859-1" ---------------------------------------- > Subject: RE: [Haskell-beginners] making function problem (chapter 6 of > Programming in Haskell) > From: d...@iai.uni-bonn.de > To: rwob...@hotmail.com > Date: Tue, 9 Aug 2011 15:33:19 +0200 > > On Tue, 2011-08-09 at 13:15 +0000, Roelof Wobben wrote: > > Lets make a try > > > > > > > > ( ^) :: Int -> Int -> Int > > > > ^ x 0 = 1 > > > > ^ x y = x + x ^ (y-1) > > > nearly perfekt, only syntax for (^) is still not ok. You would have > noticed when compiling. > The "^" is by default infix (like "+"), because its a symbol and not > starting with a letter (the exact specification you can look up in your > book I think, or in the Haskell report). > If you want to use is prefix, like a "normal" function, then you have to > put it in brackets, ie. write (^). > So either write > > (^) x 0 = 1 > (^) x y = x * (x ^ (y-1)) > > or (I think this works as well) > > x ^ 0 = 1 > x ^ y = x * (x ^ (y-1)) > > Please notice also the extra brackets around x ^ (y-1) in my definition. > You may not know the precedence of * and ^. > If you eliminate the brackets, make sure you gave the right priority to > ^, that the program does not calculate (x * x) ^ (y-1). > > And, last but not least a second typo: why do you use "+" in your > definition of the power? > because of this 4 * 3 = 4 + 4 + 4 so the forumala on the second run would be 4 + 4* 3 Roelof ------------------------------ Message: 6 Date: Tue, 09 Aug 2011 16:11:27 +0200 From: Daniel Seidel <d...@iai.uni-bonn.de> Subject: Re: [Haskell-beginners] making function problem (chapter 6 of Programming in Haskell) To: Roelof Wobben <rwob...@hotmail.com> Cc: beginners@haskell.org Message-ID: <1312899087.12191.32.ca...@entwood.iai.uni-bonn.de> Content-Type: text/plain On Tue, 2011-08-09 at 13:37 +0000, Roelof Wobben wrote: > > > ---------------------------------------- > > Subject: RE: [Haskell-beginners] making function problem (chapter 6 of > > Programming in Haskell) > > From: d...@iai.uni-bonn.de > > To: rwob...@hotmail.com > > Date: Tue, 9 Aug 2011 15:33:19 +0200 > > > > On Tue, 2011-08-09 at 13:15 +0000, Roelof Wobben wrote: > > > Lets make a try > > > > > > > > > > > > ( ^) :: Int -> Int -> Int > > > > > > ^ x 0 = 1 > > > > > > ^ x y = x + x ^ (y-1) > > > > > nearly perfekt, only syntax for (^) is still not ok. You would have > > noticed when compiling. > > The "^" is by default infix (like "+"), because its a symbol and not > > starting with a letter (the exact specification you can look up in your > > book I think, or in the Haskell report). > > If you want to use is prefix, like a "normal" function, then you have to > > put it in brackets, ie. write (^). > > So either write > > > > (^) x 0 = 1 > > (^) x y = x * (x ^ (y-1)) > > > > or (I think this works as well) > > > > x ^ 0 = 1 > > x ^ y = x * (x ^ (y-1)) > > > > Please notice also the extra brackets around x ^ (y-1) in my definition. > > You may not know the precedence of * and ^. > > If you eliminate the brackets, make sure you gave the right priority to > > ^, that the program does not calculate (x * x) ^ (y-1). > > > > And, last but not least a second typo: why do you use "+" in your > > definition of the power? > > > > > because of this > > > > 4 * 3 = 4 + 4 + 4 > > > > so the forumala on the second run would be 4 + 4* 3 > > > Ok, I thought just the name of the function was a bit misleading, because "positivePower" should have been named "product". The power function is: 4 ^ 3 = 4 * 4 * 4 and the special case (if you want to handle 0 and not 1 as base case) 4 ^ 0 = 1 Cheers, Daniel. ------------------------------ Message: 7 Date: Tue, 9 Aug 2011 21:41:42 +0200 From: informationen <informatio...@gmx.de> Subject: [Haskell-beginners] What is the use of Data.List.Key merge To: beginners@haskell.org Message-ID: <20110809194142.GE1738@sirch> Content-Type: text/plain; charset=us-ascii; format=flowed Hi, what is the merge function from the Data.List.Key module useful for? Could you give me some concrete examples? Maybe one could add these examples to the module description? Kind regards Chris ------------------------------ Message: 8 Date: Tue, 9 Aug 2011 15:04:48 -0500 From: Antoine Latter <aslat...@gmail.com> Subject: Re: [Haskell-beginners] What is the use of Data.List.Key merge To: informationen <informatio...@gmx.de> Cc: beginners@haskell.org Message-ID: <cakjsnqhzan4sp+y5obmzzykpbm3i4fl6pv0dvvb1px_03_s...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Tue, Aug 9, 2011 at 2:41 PM, informationen <informatio...@gmx.de> wrote: > Hi, > > what is the merge function from the Data.List.Key module useful > for? Could you give me some concrete examples? Maybe one could > add these examples to the module description? > Have you emailed the author of the module? Not everyone reads the beginners' list - sometimes extremely targeted questions (instead of general questions) don't get quickly answered. >From reading the text at the top of the module, I would guess it's a variation on the 'mergeBy' function, except doesn't call the passed in function as often. Antoine > Kind regards > > Chris > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > ------------------------------ Message: 9 Date: Tue, 09 Aug 2011 19:34:41 -0800 From: Christopher Howard <christopher.how...@frigidcode.com> Subject: [Haskell-beginners] Why ShowS? To: Haskell Beginners <beginners@haskell.org> Message-ID: <4e41fc51.7090...@frigidcode.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Small point I'm confused about: Why is it that in the Numeric module, all the "show" functions return a "ShowS" type (String -> String) instead of just the String? The ShowS type is described as so... "The shows functions return a function that prepends the output String to an existing String. This allows constant-time concatenation of results using function composition." What is meant here by "constant-time concatenation of results using function composition"? Perhaps someone could provide an example? -- frigidcode.com theologia.indicium.us ------------------------------ Message: 10 Date: Wed, 10 Aug 2011 00:03:38 -0400 From: Brandon Allbery <allber...@gmail.com> Subject: Re: [Haskell-beginners] Why ShowS? To: Christopher Howard <christopher.how...@frigidcode.com> Cc: Haskell Beginners <beginners@haskell.org> Message-ID: <CAKFCL4XipJTzxse=FBFO2k1rC=uxvkgrplf+gy9_vox-uzb...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" On Tue, Aug 9, 2011 at 23:34, Christopher Howard < christopher.how...@frigidcode.com> wrote: > What is meant here by "constant-time concatenation of results using > function composition"? Perhaps someone could provide an example? In effect, ShowS concatenates chunks instead of strings; you could think of it as building a list of strings, except that even then concatenation means going to the end of the list to append the new item, whereas the right-biased precedence of function composition means that it's already holding a pointer to the end of the "list" (instead of the beginning, as with normal lists). So, concatenating > "the quick brown fox jumps over the lazy dog" and > "now is the time for all good endofunctors to come to the aid of their category" your choices are: (1) string concatenation: step through the list of Char to reach the end, then append the second string; this is linear in the length of "the quick brown fox...". (2) list concatenation: start with [], append "the quick brown fox...", append "now is the time...". Each concatenation is linear in the number of strings already concatenated, so becomes expensive as more stings are appended. (3) function composition: (in effect) start with (const ""), compose it with (++ "the quick brown fox...:), compose it with (++ "now is the time..."). Each concatenation is constant time, since it's simply applying (.) to what it has. In all three cases, you have essentially the same time complexity in outputting the result. -- brandon s allbery allber...@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20110810/6904f527/attachment.htm> ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 38, Issue 21 *****************************************