Statements spanning multiple lines?

Hi all, How do I write a statement that spans multiple lines? I have this function: pythagoras n = [(a,b,c) | a <-[1..n], b <-[1..n], c <-[1..n], a <= b, b < c, a*a + b*b == c*c] This should all be in one line. I know some ways to make the line shorter, like defining local functions and using 'filter'. But the code would be clearer if I could just make this one statement span several lines. Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. /

On 12/22/05, Daniel Carrera
Hi all,
How do I write a statement that spans multiple lines?
I have this function:
pythagoras n = [(a,b,c) | a <-[1..n], b <-[1..n], c <-[1..n], a <= b, b < c, a*a + b*b == c*c]
This should all be in one line. I know some ways to make the line shorter, like defining local functions and using 'filter'. But the code would be clearer if I could just make this one statement span several lines.
Indent the second line: pythagoras n = [(a,b,c) | a <-[1..n], b <-[1..n], c <-[1..n], a <= b, b < c, a*a + b*b == c*c] /g -- We have lingered in the chambers of the sea By sea-girls wreathed with seaweed red and brown Till human voices wake us, and we drown.

J. Garrett Morris wrote:
Indent the second line:
pythagoras n = [(a,b,c) | a <-[1..n], b <-[1..n], c <-[1..n], a <= b, b < c, a*a + b*b == c*c]
Thanks! Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. /

Daniel Carrera wrote:
Hi all,
How do I write a statement that spans multiple lines?
I have this function:
pythagoras n = [(a,b,c) | a <-[1..n], b <-[1..n], c <-[1..n], a <= b, b < c, a*a + b*b == c*c]
This should all be in one line. I know some ways to make the line shorter, like defining local functions and using 'filter'. But the code would be clearer if I could just make this one statement span several lines.
Haskell's layout rules mean that you have to keep intenting at the beginning of a line to continue a definition. Try something like... pythagoras n = [(a,b,c) | a <- [1..n], b <- [1..n], c <- [1..n], a <= b, b < c, a*a + b*b == c*c ] ...or... pythagoras n = [(a,b,c) | a <- [1..n], b <- [1..n], c <- [1..n], a <= b, b < c, a*a + b*b == c*c ] ...See also... http://www.haskell.org/onlinereport/lexemes.html#lexemes-layout Greg Buchholz

You might also like to try the slightly more efficient... pyth n = [(a,b,c) | a <- [1..n], b <- [a..n], c <- [a+1..n], a*a + b*b == c*c ] Greg Buchholz

Greg Buchholz wrote:
You might also like to try the slightly more efficient...
pyth n = [(a,b,c) | a <- [1..n], b <- [a..n], c <- [a+1..n], a*a + b*b == c*c ]
Cool. I'm amazed that actually works. I've been writing filters upon filters in all my functions because I didn't realize you could write things like that. Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. /

Hello Greg, Thursday, December 22, 2005, 8:15:08 PM, you wrote: GB> You might also like to try the slightly more efficient... GB> pyth n = [(a,b,c) | a <- [1..n], GB> b <- [a..n], GB> c <- [a+1..n], "c <- [b+1..n]" is even better :) GB> a*a + b*b == c*c ] -- Best regards, Bulat mailto:bulatz@HotPOP.com
participants (4)
-
Bulat Ziganshin
-
Daniel Carrera
-
Greg Buchholz
-
J. Garrett Morris