0
votes

I'm trying to run this textbook example but I keep getting this error:

* Couldn't match expected type `Integer -> t'
              with actual type `[Char]'
* The function `showPerson' is applied to two arguments,
  but its type `People -> [Char]' has only one
  In the expression: showPerson "charles" 18
  In an equation for `it': it = showPerson "charles" 18
* Relevant bindings include it :: t (bound at <interactive>:38:1)

I don't understand why I'm getting this error. I'm inputting the correct types.
My code is:

type Name = String 
type Age = Int
data People = Person Name Age

showPerson :: People -> String
showPerson (Person a b) = a ++ " -- " ++ show b
1

1 Answers

4
votes

Your showPerson function, as declared, has only one argument. This argument is of type People.

However, judging by the error you're quoting, you are trying to call this function with two arguments - "charles" and 18. The first argument is of type String, second - of type Int.

This is what the compiler is trying to tell you when it says:

The function `showPerson' is applied to two arguments, 
but its type `People -> [Char]' has only one

To correctly call your function, you need to first create a value of type People, then pass that value to the function as argument:

p = Person "charles" 18
showPerson p

Or the same thing in one line:

showPerson (Person "charles" 18)