[Haskell-beginners] Drawing Information from a function already defined

Clockwork PC clockworkpc at gmail.com
Wed Jul 20 15:45:52 CEST 2011


Greetings Haskell community,

This is my first ever post so please be gentle...

Here's where I got to:

Jumped into GHCi:

GHCi, version 7.0.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.

Defined my function:

Prelude> let rightTriangles = [ (a,b,c) | c <- [1..10], b <- [1..10], a <-
[1..10], a^2 + b^2 == c^2 ]

Tested my function:

Prelude> rightTriangles
[(4,3,5),(3,4,5),(8,6,10),(6,8,10)]

Now, I want to define a refinement of this that will only select values
whose total is 24.

I could write it so:

let rightTriangles = [ (a,b,c) | c <- [1..10], b <- [1..10], a <- [1..10],
a^2 + b^2 == c^2,* a+b+c == 24*]

However, it seems like a bit of a waste if I already have "rightTriangles"
defined.

I tried a few things, but none of them worked:

Prelude> let rightTriangles` = rightTriangles, a+b+c == 24

<interactive>:1:21: parse error on input `='
Prelude> let rightTriangles` = rightTriangles | a+b+c == 24

<interactive>:1:21: parse error on input `='
Prelude> let rightTriangles` = [rightTriangles, a+b+c == 24]

<interactive>:1:21: parse error on input `='
Prelude> let rightTriangles` = [rightTriangles | a+b+c == 24]

<interactive>:1:21: parse error on input `='

Basically, I'm trying to work out how to draw data from a list already to
hand.

Alexander
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110720/6d10fdf3/attachment.htm>


More information about the Beginners mailing list