Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7195579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:36:23+00:00 2026-05-28T20:36:23+00:00

In Haskell ghci, I tried Prelude> :load filename.hs Ok, modules loaded: Main. unfortunately I

  • 0

In Haskell ghci, I tried

Prelude> :load filename.hs
Ok, modules loaded: Main.

unfortunately I can’t run any of the functions defined in the file. I compiled the file without any errors, but calling function gives an error, “Not in scope: (function name)”. The strange thing is, awhile earlier I had no problem running this…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:36:23+00:00Added an answer on May 28, 2026 at 8:36 pm

    The problem is that your editor is compiling the code with something like

    $ ghc foo.hs
    

    Since your file doesn’t have a module declaration, GHC assumes the module is called Main, since you didn’t specify otherwise and, since it’s compiling a full program, doesn’t export any of the definitions other than main; that is, it acts as if you have a module declaration like:

    module Main (main) where
    

    Whereas GHCi defaults to:

    module Main where
    

    These module declarations specify the name of the module you’re compiling, and which values are exported. With the first declaration, only main is exported from the module; with the second case, every top-level value is exported. Values that aren’t exported can’t be accessed from outside the module, which is why you get the “not in scope” errors in GHCi.

    GHCi’s inconsistent behaviour is presumably to make testing code easier; you don’t have to have a module declaration to load a file and use its definitions. The solution is to put module Main where (or some other module name) at the top of your file, which explicitly exports everything. Personally, I think this behaviour is confusing, and the behaviour of GHC and GHCi should probably be changed to be consistent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I :load a Haskell script into GHCi, it changes the prompt from Prelude>
I can do something like this in Haskell: #!/usr/bin/runghc main=putStrLn Hello World Then I
I'm using ghci to do some incremental development using Emacs' run-haskell . Every once
I tried to test Haskell performance, but got some unxepectedly poor results: -- main
After reading this article on writing polyvariadic functions in Haskell , I tried to
I'm complete newbie on Haskell. My Haskell script with GHCi , Prelude> let a
I'm new to Haskell. I'm using ghci . I know I can move through
First off I am using ghci under ubuntu 11.10 to run the haskell code.
In Haskell, I can check a function's type in ghci by using :t :
According to a number of tutorials (including Real World Haskell) one can, using ghci

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.