0
votes

I would like to know how to take a list of tuples as a parameter or if there is an easier solution.

I am new to Haskell (only started a week ago) and I made this function to check if the tuple acts as a Pythagorean Triple.

pyTheorem (a,b,c) = a ^ 2 + b ^ 2 == c ^ 2

let x = pyTheorem (3,4,5)  

So how would I define a function where it takes a list of tuples and returns the tuples that are Pythagorean Triples? Also, if there is a better way of doing this, please elaborate.

I looked up some similar questions but I couldn't find something that seemed to fit this example.

Side Note: I find that some of the examples in LYAH I can't seem to use in the online terminal: https://ghc.io/

So I am using http://www.tutorialspoint.com/compile_haskell_online.php instead. Are there any big differences I should be aware of?

Thanks.

1

1 Answers

5
votes

I think is all you need

filterPy : [(Int,Int,Int)] -> [(Int,Int,Int)]
filterPy ls = filter pyTheorem ls

Real afficionados would also write it 'point free'

filterPy = filter pyTheorem