0
votes

I'm learning Haskell via Learn You a Haskell and I'm pretty sure he went over this at some point but I can't figure out where. Say I want to have a function return a pair, list of pairs, or general tuple. How is the type signature for this written? For example, for some given even number I want to return the list of unique pairs of primes that add up to it. I have a function isPrime that tells whether or not an Int is a prime.

pairs :: Int -> [(Int a, Int b)]
pairs n
  | n < 4 = []
  | odd n = []
  | otherwise = [(a, b) | a < b, isPrime a, isPrime b, a+b == 1]

When I try to compile this, I get the error saying "Int has too few arguments." So I tried the following syntax instead:

pairs :: Int -> [((Int a), (Int b))]

But I got the same error. So in general how does typesetting functions involving pairs work?

1
What two primes will add up to 1?chepner
@chepner 3 and -2, naturally.Daniel Wagner

1 Answers

4
votes

Your problem isn't one of formatting. Int a and Int b are ill-kinded. Int can't be applied because it isn't a (type-level) function. You just want Int -> [(Int, Int)].