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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:52:21+00:00 2026-05-23T00:52:21+00:00

Is there any library in hackage that can parse haskell code and check if

  • 0

Is there any library in hackage that can parse haskell code and check if it is valid code or not?

I’m willing to play a bit with an evolutionary model and I want to check if produced strings of code will compile without having to write them to the disk and run the compiler.

Ideally it would be nice to be able to run the code in the strings too, but only checking the validity of the code is ok.

If you know about parser libraries (in haskell) that check for other languages (lisp, C,…)it would be nice too.

  • 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-23T00:52:22+00:00Added an answer on May 23, 2026 at 12:52 am

    For parsing Haskell code, you can use either

    • haskell-src
    • or haskell-src-exts

    The latter handles all of the GHC extensions (and then some), while the former parses only Haskell 98. Here’s an example of usage:

    Prelude> import Language.Haskell.Exts.Parser
    
    Prelude Language.Haskell.Exts.Parser> parseModule "main = putStrLn \"Hello\""
    ParseOk (Module (SrcLoc {srcFilename = "<unknown>.hs", srcLine = 1, srcColumn = 1}) (ModuleName "Main") [] Nothing (Just [EVar (UnQual (Ident "main"))]) [] [PatBind (SrcLoc {srcFilename = "<unknown>.hs", srcLine = 1, srcColumn = 1}) (PVar (Ident "main")) Nothing (UnGuardedRhs (App (Var (UnQual (Ident "putStrLn"))) (Lit (String "Hello")))) (BDecls [])])
    
    Prelude Language.Haskell.Exts.Parser> parseModule "main == putStrLn \"Hello\""
    ParseFailed (SrcLoc {srcFilename = "<unknown>.hs", srcLine = 1, srcColumn = 25}) "TemplateHaskell is not enabled"
    

    Note that even if the code parses correctly, it doesn’t mean it will typecheck:

    Prelude Language.Haskell.Exts.Parser> parseModule "main = putStrLn2 \"Hello\""
    ParseOk (Module (SrcLoc {srcFilename = "<unknown>.hs", srcLine = 1, srcColumn = 1}) (ModuleName "Main") [] Nothing (Just [EVar (UnQual (Ident "main"))]) [] [PatBind (SrcLoc {srcFilename = "<unknown>.hs", srcLine = 1, srcColumn = 1}) (PVar (Ident "main")) Nothing (UnGuardedRhs (App (Var (UnQual (Ident "putStrLn2"))) (Lit (String "Hello")))) (BDecls [])])
    

    So for your specific use case, it is probably better to use GHC API which also lets you typecheck parsed code, or just run ghc -c on your file.

    For parsing C code, there is language-c.

    If you need to parse some other language, take a look at this category on Hackage. For example, here’s a parser for S-expressions.

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

Sidebar

Related Questions

is there any library that parse a source code of C++ to produce lets
Is there any library out there that I can use to create epub files
Is there any library that can be used for analyzing (nlp) simple english text.
Is there any library, preferably in python but at least open source, that can
Is there any library that can produce server-side pie charts using Ruby? Such as
Is there any Library for .NET that returns SPARQL results in some structured List
Is there any Java library that supports hierarchical column? For example (the first three
Is there any library that covers ISO standards of international abbreviations, formats and other,
Is there any library that allows to create a Carbon application using C++ classes?
Are there any library or function that performs a bash-like glob expansion for emacs

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.