Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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' ".

like image 274
gatoatigrado Avatar asked Jan 26 '12 20:01

gatoatigrado


1 Answers

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.

like image 170
C. A. McCann Avatar answered Oct 20 '22 21:10

C. A. McCann