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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:05:59+00:00 2026-06-11T12:05:59+00:00

As an exercise to learn Haskell (and torture myself), I am considering writing a

  • 0

As an exercise to learn Haskell (and torture myself), I am considering writing a configurable Haskell code beautifier.

It will support a configuration file written in JSON or YAML (or something better?) that specifies choices like sorting imports, sorting/grouping data and class statements, number of lines between sections, etc.

I am looking for a parser for Haskell 98 that generates an abstract syntax tree (AST) and retains comments. Parsing GHC, with its language extensions, will be a bonus.

In the absence of such a thing, I guess I can write a recursive-descent parser or one using Parsec or a parser generator. Maybe rolling my own will increase the learning (and torture :-)).

Is there a complete Haskell->AST parser available under one of the open source licenses? If I make any progress on this project, I’ll put it up on github.

  • 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-11T12:06:00+00:00Added an answer on June 11, 2026 at 12:06 pm

    There is a parser available in the haskell-src-exts package. Not only does the parser parse most of the GHC extensions; it also recognizes common extensions such as syntactic XML literals and so on. You should use the parseModuleWithComments function if you also want to gain access to comment information.

    Note, however, that the comments aren’t stored in the actual syntax tree; they are stored as a separate list of comments with location information. It should be rather trivial to include the comments in the tree, if you really need to have them there, by merging the tree with the list using a linear merging algorithm (both sequences can be considered “sorted”). The comments can even be stored along with associated AST nodes, because “annotated” ASTs can contain arbitrary meta data in each node (by default, only SrcSpanInfo). The reason why this hasn’t been done in the actual haskell-src-exts package is presumably because the AST parser was written before the comment parser.

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

Sidebar

Related Questions

I'm writing a real NumericUpDown/Spinner control as an exercise to learn custom control authoring.
I am trying to learn C++ myself by reading a book and do exercise
I am new to functional programming, and now learn Haskell. As an exercise I
I'm trying to learn some Template Haskell. As an exercise, I wrote a function
I'm trying to learn some Template Haskell. As an exercise, I wrote a function
I'm trying to learn PHP, and I figured I'd make myself a simple exercise
So I've been working the last exercise of Learn Python the Hard Way and
I'm starting to learn C++ and as an exercise decide to implement a simple
I'm on Chapter 33 of Learn Ruby the Hard Way. Extra credit exercise 1
I was trying an exercise of deleting lines from a file not starting with

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.