1
votes

I am guessing this is a total beginners error. I have a hs-file in it I have written

let mylist = [1,2,3]

When I run it using :load in ghci I get the following error

parse error (possibly incorrect indentation)

The statement works when I am in Prelude mode. So basically I am wondering why is this not working when loading a file, and what's the difference between Prelude and Main?

1
Can you post the program source code and place it in {} tags? - octopusgrabbus
That was all I had written. Misstook Haskell for Python :) - Reed Richards

1 Answers

7
votes

In GHCi the syntax is a little different because it acts sort of like you're in a do-block, so you have to use the let x = ... form. In a Haskell source file you can just drop the let and write:

mylist = [1,2,3]

As for the difference between Prelude and Main, the Prelude is a standard module which defines the most common Haskell types and functions, and it's imported by default into every Haskell module.

Main is just the default name for a module that does not have module Foo where ... at the top.

When using GHCi with default settings, the prompt shows which modules are currently in scope. If you just started GHCi without loading a file, this will be just the Prelude, so the prompt looks like this:

Prelude>

After loading a module, the prompt changes to show the new module that was brought into scope. As mentioned previously, this will be Main if you didn't give it a different name.

*Main>

The asterisk means that the module has been loaded in interpreted mode, which means that everything that is in scope in the module will also be in scope at the GHCi prompt, including stuff imported from other modules such as the Prelude.

You can bring additional modules into scope by using the :m command. Notice how the prompt changes to show the additional module.

*Main> :m + Data.List
*Main Data.List> 

For more information, type :help in GHCi or read the GHCi chapter of the GHC User's Guide.