0

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?

3
  • 2
    What two primes will add up to 1? Commented Mar 14, 2017 at 0:25
  • See learnyouahaskell.com/… Commented Mar 14, 2017 at 2:09
  • @chepner 3 and -2, naturally. Commented Mar 14, 2017 at 3:03

1 Answer 1

4

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)].

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.