Ticket #3670 (closed feature request: fixed)

Opened 4 years ago

Last modified 4 years ago

Allow RULES for higher-ranked terms

Reported by: rl Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.13
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty:
Test Case: simplCore/should_compile/rule2.hs Blocked By:
Blocking: Related Tickets:

Description

Here is a small code sample:

foo :: (forall m. m a -> m b) -> m a -> m b
foo f = f

bar :: (forall m. m a -> m a) -> m a -> m a
bar f = f

I'd like to specialise foo to bar whenever possible but there seems to be no way of doing so. This doesn't work:

{-# RULES "foo/bar" foo = bar #-}

GHC complains:

    Cannot match a monotype with `(forall (m1 :: * -> *). m1 a -> m1 b)
                                  -> m a
                                  -> m b'

Adding a signature to the rhs of the rule doesn't help. GHC doesn't accept signatures in the lhs. The following works, of course, but it's not as general:

{-# RULES "foo/bar" forall (f :: (forall m. m a -> m a)). foo f = bar f #-}

Change History

Changed 4 years ago by simonpj

  • status changed from new to closed
  • failure set to None/Unknown
  • resolution set to fixed
  • testcase set to simplCore/should_compile/rule2.hs

Good idea. Fixed by

Tue Nov 17 12:54:17 GMT 2009  simonpj@microsoft.com
  * Improvement to typecheck higher-rank rules better
  
  See Note [Typechecking rules] in TcRules.  
  Suggested by Roman

    M ./compiler/typecheck/TcRules.lhs -5 +20

Simon

Note: See TracTickets for help on using tickets.