Re: [Haskell-cafe] First time haskell - parse error!

2010-03-10 Thread Sebastian Fischer
On Mar 10, 2010, at 8:47 AM, Ketil Malde wrote: I think it is better style to avoid this kind of one-off named values. I much prefer: then Golds ++show (gold s g)++... For some reason, this is a style isse that doesn't get much attention At the end of the Section on function

Re: [Haskell-cafe] First time haskell - parse error!

2010-03-10 Thread Miguel Mitrofanov
Maybe it's just me, but I think composition chain is MUCH easier to read. When readning, I'd probably transform the last version to the previous one by hand, just to make it more comprehensible. Sebastian Fischer wrote: On Mar 10, 2010, at 8:47 AM, Ketil Malde wrote: I think it is better

Re: [Haskell-cafe] First time haskell - parse error!

2010-03-10 Thread Ketil Malde
Miguel Mitrofanov miguelim...@yandex.ru writes: Maybe it's just me, but I think composition chain is MUCH easier to read. I definitely agree. [Cited from Learn You a Haskell for Great Good] oddSquareSum :: Integer oddSquareSum = sum . takeWhile (1) . filter odd . map (^2) $

Re: [Haskell-cafe] First time haskell - parse error!

2010-03-10 Thread Colin Adams
On 10 March 2010 11:21, Ketil Malde ke...@malde.org wrote: [Cited from Learn You a Haskell for Great Good]     oddSquareSum :: Integer     oddSquareSum = sum . takeWhile (1) . filter odd . map (^2) $ [1..] To me, the first one is very clear, and exposes the function as what it is: a

Naming and coding style (was: [Haskell-cafe] First time haskell - parse error!)

2010-03-10 Thread Ketil Malde
Colin Adams colinpaulad...@googlemail.com writes: Named values are just like comments, which IMO also should be kept to a bare minimum.  A bit tongue in cheek: If you need a name to understand what a function does, or a comment to understand how it does it, then your code is too complicated.

Re: [Haskell-cafe] First time haskell - parse error!

2010-03-10 Thread Sebastian Fischer
On Mar 10, 2010, at 12:21 PM, Ketil Malde wrote: Introducing names means that I need to keep the temporary definitions in my head, and I think takeWhile (1) is as clear as it can get. And while a name can be misleading (belowLimit is a boolean, no?) or flat out wrong, the definition has

Re: Naming and coding style (was: [Haskell-cafe] First time haskell - parse error!)

2010-03-10 Thread Daniel Fischer
Am Mittwoch 10 März 2010 13:03:59 schrieb Ketil Malde: never introduce names if it increases the size of your program.  (Corrolary: don't name things that aren't referred to at least twice) Objection! If the final result of your function is a combination of a handful or two of long (and

Re: [Haskell-cafe] First time haskell - parse error!

2010-03-10 Thread Stephen Tetley
Hello all Algorithmically oddSquareSum is a bit below par though... oddSquareSum :: Integer oddSquareSum = sum . takeWhile (1) . filter odd . map (^2) $ [1..] Why filter out the evens after generating them? oos1 :: Integer oss1 = sum . takeWhile (1) $ map (^2) odds where odds

Re: [Haskell-cafe] First time haskell - parse error!

2010-03-10 Thread Max Rabkin
On Wed, Mar 10, 2010 at 3:53 PM, Stephen Tetley stephen.tet...@gmail.com wrote:   where odds = iterate (+2) 1 Or odds = [1,3..] --Max ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] First time haskell - parse error!

2010-03-10 Thread Stephen Tetley
Hi Max Nice! - I didn't know about that syntax. PS I should have said Why generate the evens only to filter them out? On 10 March 2010 13:57, Max Rabkin max.rab...@gmail.com wrote: [Snip] Or odds = [1,3..] ___ Haskell-Cafe mailing list

Re: [Haskell-cafe] First time haskell - parse error!

2010-03-10 Thread Ketil Malde
Sebastian Fischer s...@informatik.uni-kiel.de writes: I do not agree that introducing names locally for compositions is *always* a bad idea, even if used only once. Well, of course I do that all the time too. :-) (Choosing names that are misleading or flat out wrong is of course always a

Re: [Haskell-cafe] First time haskell - parse error!

2010-03-10 Thread Daniel Fischer
Am Mittwoch 10 März 2010 14:53:32 schrieb Stephen Tetley: Hello all Algorithmically oddSquareSum is a bit below par though... oddSquareSum :: Integer oddSquareSum = sum . takeWhile (1) . filter odd . map (^2) $ [1..] Why filter out the evens after generating them? oos1 ::

Re: [Haskell-cafe] First time haskell - parse error!

2010-03-10 Thread Ketil Malde
Stephen Tetley stephen.tet...@gmail.com writes: oddSquareSum :: Integer oddSquareSum = sum . takeWhile (1) . filter odd . map (^2) $ [1..] Why filter out the evens after generating them? In other words: sum . takeWhile (1) . filter odd . map (^2) $ [1..] Since odd (x^2) = odd x:

Re: [Haskell-cafe] First time haskell - parse error!

2010-03-10 Thread Tillmann Rendel
Ketil Malde wrote: Also, good names are harder than they sound: I don't think 'belowLimit' is a good name for 'takeWhile (1)', for instance. I certainly couldn't guess what it was for without looking at the implementation, which kind of defeats the purpose of names for improving code

[Haskell-cafe] First time haskell - parse error!

2010-03-09 Thread boblettoj
Hi, i am getting an error when trying to compile this part of my program, its my first time using haskell and as lovely as it is it didn't give me very much to go on in the error message! codescore :: String - String - String score [s] [] = false score [s] [g] = if valid 4 g

Re: [Haskell-cafe] First time haskell - parse error!

2010-03-09 Thread Deniz Dogan
2010/3/9 boblettoj bobletto...@msn.com: Hi, i am getting an error when trying to compile this part of my program, its my first time using haskell and as lovely as it is it didn't give me very much to go on in the error message! codescore :: String - String - String score [s] [] = false

Re: [Haskell-cafe] First time haskell - parse error!

2010-03-09 Thread Paul Johnson
Thats because you can't put a where in a then clause. Move the where stuff to the end of the function. On 09/03/10 19:04, boblettoj wrote: Hi, i am getting an error when trying to compile this part of my program, its my first time using haskell and as lovely as it is it didn't give me very

Re: [Haskell-cafe] First time haskell - parse error!

2010-03-09 Thread S. Doaitse Swierstra
On 9 mrt 2010, at 20:04, boblettoj wrote: Hi, i am getting an error when trying to compile this part of my program, its my first time using haskell and as lovely as it is it didn't give me very much to go on in the error message! codescore :: String - String - String score [s] [] =

Re: [Haskell-cafe] First time haskell - parse error!

2010-03-09 Thread Sebastian Hungerecker
On 09.03.2010 20:04, boblettoj wrote: score :: String - String - String score [s] [] = false score [s] [g] = if valid 4 g then (s1 ++ s2 ++ s3 ++ s4) where s1 = Golds s2 = show (gold s g) s3 = , Silvers s4 = show

Re: [Haskell-cafe] First time haskell - parse error!

2010-03-09 Thread Brent Yorgey
On Tue, Mar 09, 2010 at 08:42:44PM +0100, Sebastian Hungerecker wrote: On 09.03.2010 20:04, boblettoj wrote: score :: String - String - String score [s] [] = false score [s] [g] = if valid 4 g then (s1 ++ s2 ++ s3 ++ s4) where s1 = Golds s2 = show

Re: [Haskell-cafe] First time haskell - parse error!

2010-03-09 Thread Kyle Murphy
Seems like a good time to mention the Maybe monad looks like it would be a good fit here. score :: String - String - Maybe String score s [] = Nothing score s g = if valid 4 g then let s1 = Golds s2 = show (gold s g) s3 = , Silvers s4 = show (silver s g)

Re: [Haskell-cafe] First time haskell - parse error!

2010-03-09 Thread Ketil Malde
S. Doaitse Swierstra doai...@cs.uu.nl writes: then (s1 ++ s2 ++ s3 ++ s4) where s1 = Golds s2 = show (gold s g) s3 = , Silvers s4 = show (silver s g) If you want to keep the definitions local to the expression you should write