Haskell Errors: "missing accompanying binding" and "not to scale",
I created a code snippet:
intToDigit :: Char -> Int ord :: Char -> Int intToDigit c = ord c - ord 'a' However, when I run it, I get the following error message:
ChangeVowels.hs: 2: 1: Type signature for `ord 'does not have an accompanying binding
ChangeVowels.hs: 4: 16: Out of scope: `ord '
ChangeVowels.hs: 4: 24: Out of scope: `ord '
I tried it using Import data.char , but this does not work either.
You need to provide an implementation for the ord function. Here you specified the signature for ord , but not implemented.
Or you can use your own ord Haskell function, i.e. Char.ord .
Delete the line:
ord :: Char -> Int Or give it a definition.
And it's a bad idea to name your function intToDigit, while it is already used in Data.Char to do the opposite of what you are doing.
Your Data.Char.digitToInt function, and its implementation also works with hexadecimal:
digitToInt :: Char -> Int digitToInt c | isDigit c = ord c - ord '0' | c >= 'a' && c <= 'f' = ord c - ord 'a' + 10 | c >= 'A' && c <= 'F' = ord c - ord 'A' + 10 | otherwise = error ("Char.digitToInt: not a digit " ++ show c) -- sigh This is actually not what you defined ... why is 'a' in your code?