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. Equivalence (or not) of lists (Lawrence Wickert) 2. Re: Equivalence (or not) of lists (Sylvain Henry) 3. Re: Equivalence (or not) of lists (Francesco Ariis) 4. Re: Equivalence (or not) of lists (Francesco Ariis) 5. Equivalence (or not) of lists (Lawrence Wickert) 6. Request for Code Review: Dice Game Distribution (Jan Brusch) ---------------------------------------------------------------------- Message: 1 Date: Sat, 12 Nov 2016 20:20:19 +0000 From: Lawrence Wickert <skippy_...@hotmail.com> To: "beginners@haskell.org" <beginners@haskell.org> Subject: [Haskell-beginners] Equivalence (or not) of lists Message-ID: <co1pr14mb10168fdc114706981643775eee...@co1pr14mb1016.namprd14.prod.outlook.com> Content-Type: text/plain; charset="iso-8859-1" Hello all, I am a rank beginner to functional languages. Working through Lipovaca's book, up to Chapter 3. Ok, setup this function in editor and compiled: length' :: (Num b) => [a] -> b length' [] = 0 length' (_:xs) = 1 + length' xs skippy@skippy:~$ ghci GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help Prelude> :l baby [1 of 1] Compiling Main ( baby.hs, interpreted ) Ok, modules loaded: Main. *Main> length' [1,2,3] 3 *Main> 1:2:3:[] [1,2,3] *Main> length' 1:2:3:[] <interactive>:5:9: Could not deduce (Num [a0]) arising from the literal '1' from the context (Num a) bound by the inferred type of it :: Num a => [a] at <interactive>:5:1-16 The type variable 'a0' is ambiguous In the first argument of 'length'', namely '1' In the first argument of '(:)', namely 'length' 1' In the expression: length' 1 : 2 : 3 : [] *Main> Obviously, there is something I don't understand about the apparent non-equivalence of the lists [1,2,3] and 1:2:3:[]I am guessing that the solution is contained in that error message but I can't quite decipher it. Thanks for any help. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20161112/f503d1ce/attachment-0001.html> ------------------------------ Message: 2 Date: Sat, 12 Nov 2016 21:30:07 +0100 From: Sylvain Henry <sylv...@haskus.fr> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Equivalence (or not) of lists Message-ID: <c47bf925-cab3-bc1e-e07e-82a23d917...@haskus.fr> Content-Type: text/plain; charset="utf-8"; Format="flowed" Hi, > length' 1:2:3:[] is equivalent to: > (length' 1):2:3:[] hence the error. Try: > length' (1:2:3:[]) Sylvain On 12/11/2016 21:20, Lawrence Wickert wrote: > Hello all, > > I am a rank beginner to functional languages. Working through > Lipovaca's book, up to Chapter 3. > > Ok, setup this function in editor and compiled: > > length' :: (Num b) => [a] -> b > length' [] = 0 > length' (_:xs) = 1 + length' xs > > > skippy@skippy:~$ ghci > GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help > Prelude> :l baby > [1 of 1] Compiling Main ( baby.hs, interpreted ) > Ok, modules loaded: Main. > *Main> length' [1,2,3] > 3 > *Main> 1:2:3:[] > [1,2,3] > *Main> length' 1:2:3:[] > > <interactive>:5:9: > Could not deduce (Num [a0]) arising from the literal ‘1’ > from the context (Num a) > bound by the inferred type of it :: Num a => [a] > at <interactive>:5:1-16 > The type variable ‘a0’ is ambiguous > In the first argument of ‘length'’, namely ‘1’ > In the first argument of ‘(:)’, namely ‘length' 1’ > In the expression: length' 1 : 2 : 3 : [] > *Main> > > > Obviously, there is something I don't understand about the apparent > non-equivalence of the lists [1,2,3] and 1:2:3:[]I am guessing that > the solution is contained in that error message but I can't quite > decipher it. > > Thanks for any help. > > > > > _______________________________________________ > 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/20161112/452b270b/attachment-0001.html> ------------------------------ Message: 3 Date: Sat, 12 Nov 2016 21:27:21 +0100 From: Francesco Ariis <fa...@ariis.it> To: beginners@haskell.org Subject: Re: [Haskell-beginners] Equivalence (or not) of lists Message-ID: <20161112202346.ga2...@casa.casa> Content-Type: text/plain; charset=us-ascii On Sat, Nov 12, 2016 at 08:20:19PM +0000, Lawrence Wickert wrote: > Hello all, > > I am a rank beginner to functional languages. Working through > Lipovaca's book, up to Chapter 3. > > [...] > > *Main> length' 1:2:3:[] Hello Lawrence, remember that function application has precedence over operators! So writing: *Main> length' 1:2:3:[] is equivalent to writing *Main> (length' 1) :2:3:[] (which is not what you want). If you add parentheses, your expression works again! *Main> length' (1:2:3:[]) ------------------------------ Message: 4 Date: Sat, 12 Nov 2016 21:29:22 +0100 From: Francesco Ariis <fa...@ariis.it> To: beginners@haskell.org Subject: Re: [Haskell-beginners] Equivalence (or not) of lists Message-ID: <20161112202346.ga2...@casa.casa> Content-Type: text/plain; charset=us-ascii On Sat, Nov 12, 2016 at 08:20:19PM +0000, Lawrence Wickert wrote: > Hello all, > > I am a rank beginner to functional languages. Working through > Lipovaca's book, up to Chapter 3. > > [...] > > *Main> length' 1:2:3:[] Hello Lawrence, remember that function application has precedence over operators! So writing: *Main> length' 1:2:3:[] is equivalent to writing *Main> (length' 1) :2:3:[] (which is not what you want). If you add parentheses, your expression works again! *Main> length' (1:2:3:[]) ------------------------------ Message: 5 Date: Sat, 12 Nov 2016 20:38:37 +0000 From: Lawrence Wickert <skippy_...@hotmail.com> To: "beginners@haskell.org" <beginners@haskell.org> Subject: [Haskell-beginners] Equivalence (or not) of lists Message-ID: <co1pr14mb101622acdda51a0f18ca7e04ee...@co1pr14mb1016.namprd14.prod.outlook.com> Content-Type: text/plain; charset="iso-8859-1" Thanks, Sylvain. That works and I think I understand the difference now. Larry -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20161112/815bc62c/attachment-0001.html> ------------------------------ Message: 6 Date: Sat, 12 Nov 2016 22:43:13 +0100 From: Jan Brusch <jan.bru...@gmail.com> To: beginners@haskell.org Subject: [Haskell-beginners] Request for Code Review: Dice Game Distribution Message-ID: <caosrd+4eiksnvg5yswwdmzokqrm0wt-tx5d1s6frnok7bu8...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Hi, I'm currently learning Haskell and as a first project I wrote a little helper for a dice game. It's very short. Nonetheless I would really appreciate a little Code Review or any other input. The Game: Each player writes down the numbers from 1 to 42. Each turn you roll 3 dice (6-sided). The rolling player can cross of any one number that he can construct from the three dice using the math operators +, -, *, /. First player to cross off all numbers wins. The Helper: Calculates the reachable numbers for each dice roll. It the aggregates a count for each number, from how many dice rolls it can be reached. E.g.: There are 216 possible dice rolls (6^3), the number 2 can be reached form 171 of them. The helper gives out the data in JSON format that can be read by NVD3 to be displayed in a browser. The graph helps you to make a decision on which number you should prefer to cross off with your current roll. The Code: http://lpaste.net/338358 The Graph: http://imgur.com/a/NSDT8 Looking forward to any feedback and thanks in advance Jan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20161112/d9ab4cbe/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 101, Issue 7 *****************************************