Nathaniel Pisarski
Nathaniel Pisarski

Reputation: 308

The Type signature lacks an appropriate binding [Haskell]

I have been googling around to find the answer, and even came to a few questions asked here. It seems that this is an ambiguous error and I can't figure out how to solve it in my instance.

The offending code is below:

pos :: (Eq a) => [a] -> a -> Int
pos [] _ = -1
pos (x:xs) y
| not $ elem y (x:xs) = -1
| x == y =  0
| otherwise = 1 + pos xs y

-- Get the same element from another range as one element of the first range.
refPos :: (Eq a) => [a] -> [b] -> a -> b
refPos r1 r2 e1 = r2 !! (r1 `pos` e1)

letterNumber :: (Eq a, Char a) => a -> Int 
lettNumber x = refPos ['a'..'z'] [0..25] x

The text of the exact error is:

15:1 The type signature for letterNumber lacks an accompanying binding.

Originally the type signature I put was Char -> Int, but that didn't work (it said something about Eq, but I'm too new too Haskell to interpret it properly). So I changed the type signature to have an Eq class constraint. If someone can point out what is wrong or a workaround, it would be greatly appreciated as this is a doorstop problem to a project I'm working on.

Upvotes: 4

Views: 3103

Answers (1)

dave4420
dave4420

Reputation: 47052

You provide a type signature for letterNumber, but then provide a binding for lettNumber. Note the missing er.

Just rename lettNumber to letterNumber, to match the spelling in the type signature.


Also, the correct type signature for letterNumber is

letterNumber :: Char -> Int 

Upvotes: 6

Related Questions