0
votes

I've just began using haskell.. I tried to run a sample script:

import Data.List
module main where

mylength = foldr (const (+1)) 0
main = print (mylength "haskell")

I get a simple error "modules loaded, none." I have zero idea why this is happening. I'm using GHCi under win7 32bit (if that matters). Am I missing something here? the example doesn't even include the "module main where" but even without that it fails to run.

2

2 Answers

3
votes

The module line always goes before imports. And the module name should start with a capital letter.

module Main where
import Data.List

mylength = foldr (const (+1)) 0
main = print (mylength "haskell")

If this doesn't work for you, please tell us

  • the full error message you get; and
  • which version of which compiler you're using
0
votes

You don't need module line there. When you do put it in, though, it must go before any import statements.

module main where  -- Optional, in the case of main.

import Data.List

myLength :: [a] -> Int
myLength = foldr (const (+1)) 0

main = print (mylength "haskell")