Search code examples
haskellghci

My Haskell code isn't compiling because of an import error


I'm trying to run my code in my command line to double-check my work. My code works with iHaskell but not with ghci.

I'm getting this error:

test.hs:6:1: error: parse error on input ‘import’
  |
6 | import Data.Char

Here is my code:

main :: IO()
import Data.Char

...

result = f "hElLo"
main = print result

Any idea why this is not working? Thanks in advance for the help.


Solution

  • Thank you to @bradrn for the advice.

    I moved the import above the main so now it's:

    import Data.Char
    
    ...
    
    result = f "hElLo"
    main :: IO()
    main = print result