Haskell-ghci, function toUpper not found?
Asked Answered
C

1

5

I'have right now installed the ghci version 8.6.2 and following a tutorial I write:

toUpper "something"

but ghci compiler prints out:

Variable not in scope: toUpper :: [Char] -> t

Do I miss some libraries or anything else?

Collude answered 12/11, 2018 at 18:8 Comment(0)
C
10

The toUpper :: Char -> Char is not part of the Prelude, and thus not imported "implicitly".

You can import it with:

import Data.Char(toUpper)

or just:

import Data.Char

to import all functions, datatypes, etc. defined in that module.

Note that it has signature Char -> Char, so it only converts a single character to its uppercase equivalent.

You thus need to perform a mapping:

Prelude Data.Char> map toUpper "something"
"SOMETHING"
Christadelphian answered 12/11, 2018 at 18:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.