Home > Enterprise >  How to include a module to a haskell source code file
How to include a module to a haskell source code file

Time:10-06

What is the syntax to include a module in a Haskell source code file? I am writing

import Data.Maybe

at the top of my source code file however it gives the error

error: parse error on input `import'

CodePudding user response:

The reason you get this error is because you imported the module at the wrong place in the file. The import statements should be written at the top of the file, immediately after a module statement (if you use one). You thus should not import a module after you defined one (or more) types, functions, etc.

A file thus looks like:

-- module name (optional)
module MyModuleName where

-- import statements
import Data.Maybe
-- ⋮

-- functions, types, typeclasses, etc.
-- ⋮
  • Related