Reputation: 181
I am new to Haskell and functional programming in general. I am currently learning about custom data types and have the following:
data Point = Pt Double Double deriving (Show, Eq)
getValue :: Point -> Double
getValue (Pt a _) = a
I am attempting to return only one of the double values from the custom data type but am running into a problem. My console gives me the following error whenever I try to extract one of my point values: "Couldn't match expected type Integer -> Integer -> t
". Any ideas as to what I am doing wrong?
(edit from OP's comments:) I typed the following in GHCi
test Pt 1.0 1.0
Here is the entire error message :
• Couldn't match expected type ‘Integer -> Integer -> t’
with actual type ‘Double’
• The function ‘test’ is applied to three arguments,
but its type ‘Point -> Double’ has only one
In the expression:
test Pt 1 1
In an equation for ‘it’:
it = test Pt 1 1
• Relevant bindings include
it :: t (bound at <interactive>:497:1)
test
is what I renamed getValue
as.
Upvotes: 2
Views: 514
Reputation: 71119
you clearly want to do test (Pt 1.0 1.0)
.
test Pt 1.0 1.0
with no parentheses is interpreted as applying the test
function to the 3 arguments Pt
, 1.0
and 1.0
, which makes no sense and is why GHC is complaining. – Robin Zigmond, yesterday
Upvotes: 1