Error about “type signature with no binding”

后端 未结 2 669
予麋鹿
予麋鹿 2021-01-29 12:25

I have a problem with ASCII in Haskell.

fromEnum :: Char -> Int
toEnum :: Int -> Char

offset :: Int
offset = fromEnum \'A\' - fromEnum \'a\'

toUpper ::          


        
相关标签:
2条回答
  • 2021-01-29 12:45

    fromEnum and toEnum are standart functions

    please try this:

    offset :: Int
    offset = fromEnum 'A' - fromEnum 'a'
    
    toUpper :: Char -> Char
    toUpper ch = toEnum (fromEnum ch + offset)
    
    0 讨论(0)
  • 2021-01-29 12:59

    Unless you are doing this as an exercise, you should really use toUpper from module Data.Char.

    Doing this well requires to check how uppercase is defined in Unicode -- I'd rather rely on the standard library for that :)

    Also, watch out because your toUpper is not idempotent: one might expect that toUpper 'A' == 'A', for instance.

    0 讨论(0)
提交回复
热议问题