Reputation: 349
Hello everybody
I cannot understand why I get such error when I try to import a module after I have imorted a Data.Char library? Actually when I delete module Test where everything works correctly
import Data.Char
module Test where
sayHello = putStrLn "Hello, world withoutCorona!"
lenVec3 x y z = sqrt ( x ^ 2 + y ^ 2 + z ^ 2 )
sign x = (if x > 0 then 1 else 0) + (if x < 0 then -1 else 0) + 0
twoDigits2Int x y = if isDigit x && isDigit y then digitToInt x * 10 + digitToInt y else 100
Thanks in avance
Upvotes: 3
Views: 585
Reputation: 476493
A Haskell program is a set of modules. A module is structured gramatically as:
module -> module modid [exports] where body | body body -> { impdecls ; topdecls } | { impdecls } | { topdecls } modid -> conid impdecls -> impdecl1 ; … ; impdecln (n>=1) topdecls -> topdecl1 ; … ; topdecln (n>=1)
The import
declarations are the importdecls
in this grammar, and thus part of the body
. A module can exists without a module modid …
part, but if we define a module identifier, then this precedes the body
.
You thus write such module as:
module Test where
import Data.Char
-- …
Upvotes: 3
Reputation: 9767
Imports go after the module
, not before. module Name where
should be the first thing, possibly preceded only by language extensions and compiler flags:
module Test where
import Data.Char
Upvotes: 7