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 9051955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:02:49+00:00 2026-06-16T13:02:49+00:00

I’m writing a little Haskell compiler, and I want to implement as much Haskell

  • 0

I’m writing a little Haskell compiler, and I want to implement as much Haskell 2010 as possible. My compiler can parse a module, but completing modules to a program seems to be a non-trivial task. I made up some examples of tricky, but maybe valid, Haskell modules:

module F(G.x) where
  import F as G
  x = 2

Here the module F exports G.x, but G.x is the same as F.x, so module F exports x if, and only if, it exports x.

module A(a) where
  import B(a)
  a = 2

module B(a) where
  import A(a)

In this example, to resolve the exports of module A the compiler has to check if a imported from B is the same as the declared a = 2, but B exports a if, and only if, A exports a.

module A(f) where
  import B(f)

module B(f) where
  import A(f)

During resolving module A, the compiler may’ve assumed that f imported from B exists, implying that A exports f, thus B can import A(f) and export f. The only problem is that there’s no f defined anywhere :).

module A(module X) where
  import A as X
  import B as X
  import C as X
  a = 2

module B(module C, C.b) where
  import C
  b = 3

module C(module C)
  import B as C
  c = 4

Here, the module exports cause that export lists are dependent on each other and on themselves.

All these examples should be valid Haskell, as defined by the Haskell 2010 spec.

I want to ask if there is any idea how to correctly and completely implement Haskell modules?

Assume that a module contains just (simple) variable bindings, imports (possibly with as or qualified), and exports list of possibly qualified variables and module ... abbreviations. The algorithm has to be able to:

  • compute finite list of exported variables of each module
  • link every exported variable to its binding
  • link every (maybe qualified) variable used in every module to its binding
  • 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-06-16T13:02:50+00:00Added an answer on June 16, 2026 at 1:02 pm

    You may be interested in A Formal Specification for the Haskell 98 Module System.

    I’m also covering some interesting edge cases in a series of blog posts, of which only the first one is published as of now.

    Finally, I’m working on exactly that — a library that handles Haskell modules. It’s called haskell-names.

    Depending on your goals, you can simply use it in your compiler, study the source code or contribute. (Your examples will make excellent test cases.)


    To answer your question: recursive modules are handled by computing a fixed point.

    You start with a strongly connected component in the module graph. For each module in this component, you start with an assumption that it exports nothing. Then you revisit these modules, and compute new export lists based on the fresh information. You can prove that this process is monotonic — every time the export list grows (or, at least, does not shrink). Sooner or later it stops growing — then you’ve reached the fixed point.

    You can optimize this algorithm by borrowing some ideas from static analysis (that community is very good at computing fixed points), but my package currently implement the naive algorithm (code).

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I want to count how many characters a certain string has in PHP, but
I want to construct a data frame in an Rcpp function, but when I
i want to parse a xhtml file and display in UITableView. what is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using JSon response to parse title,date content and thumbnail images and place
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I want use html5's new tag to play a wav file (currently only supported
I'm interested in microtypography issues on the web. I want a tool to fix:

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.