Haskell -- any way to turn off rebindable syntax for the case of `deriving` instances?

599 views Asked by At

There's an annoying "feature" that deriving instances are also affected by the RebindableSyntax extension. Example of what I want to write:

{-# LANGUAGE RebindableSyntax #-}
import qualified Prelude
data Color = Red | Green | Blue | Periwinkle | Fuschia deriving (Prelude.Eq, Prelude.Ord)

This comes up with the error " Not in scope: `ifThenElse' ".

1

There are 1 answers

1
C. A. McCann On

That seems like a misfeature to me--the deriving clause is full of built-in magic anyway, so I'm skeptical that derived instances using rebound syntax would be useful in practice. Now, if you could also rebind the deriving clause itself and use a TH splice instead... but I digress.

I suspect the simplest and easiest solution is to use different modules. Put the data type definition in its own module, use the deriving clause there with the Prelude functions in scope, then import the type in the module using rebindable syntax. If you need further modularity in your modules, note that StandaloneDeriving also exists, and would let you define the types in one module (with RebindableSyntax active), derive the instances in another module (without RebindableSyntax), and import both from modules that actually use the type.