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

  • Home
  • SEARCH
  • 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 4033828
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:53:44+00:00 2026-05-20T11:53:44+00:00

I ran into a case using Happy (a Haskell parsing package) where the order

  • 0

I ran into a case using Happy (a Haskell parsing package) where the order of seemingly independent rules affects its behavior in a strange way.

{
module Parser where
}
%name constFoo
%name constBar
%tokentype { Token }
%error { parseError }
%token
    foo          { Foo }
    bar          { Bar }
%%
constFoo : foo { Foo }
constBar : bar { Bar }
{
parseError :: [Token] -> a
parseError _ = error "Parse error"
data Token = Bar | Foo deriving Show
}

As I understand how Happy works, both of the parses constFoo [Foo] and constBar [Bar] should succeed. However, with the above code, constFoo [Foo] succeeds but constBar [Bar] fails. If I swap the order of the rules for constFoo and constBar, the latter succeeds and the former fails.

Is there some aspect to Happy’s semantics that I’m not understanding?

  • 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-20T11:53:45+00:00Added an answer on May 20, 2026 at 11:53 am

    Edited – Happy’s syntax allows you to specify the start production with the name directive:

    %name parser constFoo
    

    This creates a function called parser and it uses constFoo as the start production.

    If you want parsers for both constFoo and constBar, this seems to be the syntax:

    %name parser1 constFoo
    %name parser2 constBar
    

    I think in your original, both named parser functions (constFoo and constBar) defaulted to the first production in the grammar (constFoo).

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

Sidebar

Related Questions

I ran into a problem using case classes and parameterized types with an upper
I ran into the case that when I had 4G off and connected to
I have not used many lambda expressions before and I ran into a case
I ran into a problem using Springsource Tool Suite when writing some groovy scripts
<XmlInfo /> I ran into problem using Perl's popular SOAP::Lite module, where it wouldn't
I ran into some trouble while using a list of arrays. So to clear
I ran into a problem today when trying to set a field using FieldInfo.SetValue()
I ran into a weird behavior from Oracle this morning... And I can't understand
I ran into this problem using EF4 and a self-referential table (implementing an adjacency
Ran into another problem using SSL and Tomcat: I've configured a keystore which contains

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.