Ticket #5324 (new feature request)

Opened 22 months ago

Last modified 22 months ago

Locally-scoped RULES

Reported by: reinerp Owned by:
Priority: normal Milestone: _|_
Component: Compiler Version: 7.0.3
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

I'd like the following to compile:

module A where

f = g where
  {-# RULES "g/h" g = h #-}
  g = undefined
  h = undefined

This doesn't currently compile, because all RULES have to be top-level.

However, GHC permits SPECIALISE pragmas at local scope; the following compiles:

module Test where

f :: Num a => a -> a
f = g where
  {-# SPECIALISE g :: Int -> Int #-}
  g :: Num b => b -> b
  g x = x + x

(Admittedly, this example discards the specialisation, but more interesting examples don't.)

I only point out that the SPECIALISE pragma succeeds, because the user manual has the comment that rules subsume the 'Obsolete SPECIALIZE syntax', but in this case they don't.

I've got a real example where I would like locally-scoped RULES, but it is rather long, so I will post it as a comment.

Change History

Changed 22 months ago by reinerp

I was writing up my real example, but I just came up with a workaround, so this ticket isn't of such importance to me now.

Changed 22 months ago by igloo

  • milestone set to 7.4.1

Thanks for the suggestion.

Changed 22 months ago by simonpj

  • milestone changed from 7.4.1 to _|_

OK. It's a reasonable request, and there's no technical reason it can't be done, but it's a bit fiddly, so I'll postpone until someone really wants it.

Note: See TracTickets for help on using tickets.