0

As some of you may know, the type inference errors in Haskell can be cryptic at times. I was trying to write a function that mapped alphabetic characters to their uppercase version, and I came up with this:

toUpper :: Char -> Char toUpper char = maybe " " (\a -> a) isValue where charMap = zip ['a' .. 'z'] ['A' .. 'Z'] isValue = lookup char charMap 

But it complains about the following:

 wordsearch.hs:2:35: Couldn't match expected type `[Char]' against inferred type `Char' Expected type: Maybe [Char] Inferred type: Maybe Char In the third argument of `maybe', namely `isValue' In the expression: maybe " " (\ a -> a) isValue 

The error is doesn't make sense to me as i'm a newbie, can anyone help?

1 Answer 1

9
" " :: [Char] ' ' :: Char 

You want maybe ' ' id isValue, not maybe " " id isValue.

Sign up to request clarification or add additional context in comments.

1 Comment

Ugh, i've got to pay more attention to these things. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.