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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:59:42+00:00 2026-05-31T17:59:42+00:00

As far as I can tell I wouldn’t think it would make any difference

  • 0

As far as I can tell I wouldn’t think it would make any difference that id1 and id2 are from a type class and id1′ and id2′ are not. I am running “ghc Rewrite” with the latest Haskell Platform (with both GHC version 7.0.4 and now 7.4.1 too), and I expect to1 to also fire.

$ ghc Rewrite
[1 of 1] Compiling RewriteProblems  ( Rewrite.hs, Rewrite.o )
Rule fired: rewrite/ez'
Rule fired: rewrite/to1'
Rule fired: rewrite/ez
Rule fired: rewrite/ez
Rule fired: Class op id2
Rule fired: Class op id2

the example:

{-# OPTIONS_GHC -O -ddump-rule-firings #-}
module RewriteProblems where

{-# RULES
"rewrite/ez"    forall a. id1 a = RDUnit
"rewrite/to1"   forall a. id2 (id2 a) = id1 a
"rewrite/ez'"   forall a. id1' a = RDUnit
"rewrite/to1'"  forall a. id2' (id2' a) = id1 a
   #-}

class Ider a where
    id1 :: a -> a
    id2 :: a -> a

data RewriteD = RDUnit

instance Ider RewriteD where
    {-# INLINE[1] id1 #-}
    {-# INLINE[1] id2 #-}
    id1 a = RDUnit
    id2 a = RDUnit

testThing1 :: RewriteD
testThing1 = id1 RDUnit

testThing2 :: RewriteD
testThing2 = id2 (id2 RDUnit)

testThing1' :: RewriteD
testThing1' = id1' RDUnit

testThing2' :: RewriteD
testThing2' = id2' (id2' RDUnit)

{-# INLINE[1] id1' #-}
{-# INLINE[1] id2' #-}
id1' :: RewriteD -> RewriteD
id2' :: RewriteD -> RewriteD
id1' a = RDUnit
id2' a = RDUnit
  • 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-31T17:59:43+00:00Added an answer on May 31, 2026 at 5:59 pm

    (several edits made throughout post with updated information)

    In your output, notice the lines Rule fired: Class op id2. These are rules automatically created by GHC for type class instances. This rule is firing first, so your own rule never gets a chance to match. If you compile with “-ddump-simpl-iterations”, you can check that the Class op rule fires in the first phase, after which your “to1” rule will never match.

    Here’s a bit of a workaround. First comment out testThing1, testThing1', and testThing2' so only testThing2 is compiled. This is the only function where “rewrite/to1” can fire, so it isolates the test case you’re looking at. Next add another rule of the form:

    "rewrite/to_id2'"   forall a. id2 a = id2' a
    

    and you’ll see this output:

    $ ghc -c foo.hs
    Rule fired: rewrite/to_id2'
    Rule fired: rewrite/to_id2'
    Rule fired: rewrite/to1'
    Rule fired: rewrite/ez
    

    The new rule is now firing instead of the class op, which allows rewrite/to1' to simplify the expression. Interestingly, it doesn’t matter if the new rule appears above or below rewrite/to1 in the list of RULES.

    I don’t know why your id2 (id2 a) rule isn’t matching whereas id2 a does. It looks like it should match (according to -dverbose-core2core), but it isn’t. I still suspect a GHC precedence bug of some type, although I also see the same behavior with ghc-7.4.1 so it isn’t 4397.

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

Sidebar

Related Questions

I'm a bit confused here. Microsoft as far as I can tell claims that
Can anyone tell my why this wouldn't compile? package main type myint int func
A hypothetical variadic template tuple class would, as far as I can tell, have
As far as I can tell, this is isn't possible, so I'm really just
As far as I can tell, the best way to do this is do
As far as I can tell the iPhone multitouch framework sends the location of
As far as I can tell i'm doing everything by the book, but the
As far as I can tell, there is no API (official or unofficial) to
As far as I can tell, Scala has definitions for the Enumeration Value class
As far as I can tell, this code is fine, and should display some

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.