For the following trivial function definitions:
printLength1::(Num a)=>String->a
printLength1 s = length s
printLength2::String->Int
printLength2 s = length s
Why aren't they the same? In what situations should I choose one over the other?
And I get this error for printLength1:
Couldn't match type `a' with `Int'
`a' is a rigid type variable bound by
the type signature for rpnc :: String -> a at test.hs:20:1
In the return type of a call of `length'
In the expression: length s
In an equation for `rpnc': rpnc s = length s
I understand this error. But how can I fix this? I already read some posts here about a variable of hard type, but still could not figure out how to fix it.
source
share