tags:

views:

76

answers:

1

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?

+8  A: 
" " :: [Char]
' ' :: Char

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

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