views:

84

answers:

1

Just wondering how to get ascii value of character in haskell? I've tried to use the 'ord' function in ghci, based on what i read here:

http://haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/Data-Char.html#6

GHCi, version 6.12.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> ord 'a'

<interactive>:1:0: Not in scope: `ord'
Prelude>

What am i doing wrong?

+3  A: 

As Travis Brown indicated in a comment, you have to import the ord function from the module Data.Char:

import Data.Char (ord)

main = print (ord 'a')

Only the Prelude module is loaded by default, all other modules have to be imported explicitly.

sth
Is this just a ghci thing? Or do i have to import these kind of modules when i'm making .hs files too?
Chris
@Chris: Only stuff defined in `Prelude` is imported by default, for other modules you have to specify additional imports.
sth
Thanks a lot sth!
Chris