Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

deriving clause with arbitrary "Constraint aliases"?

Tags:

haskell

For example, this declaration with deriving:

{-# LANGUAGE DeriveDataTypeable, ConstraintKinds #-}
import Data.Data (Data)
import Data.Typeable (Typeable)

type Constraints a = (Show a, Eq a, Ord a, Data a, Typeable a)
data A = A deriving (Constraints)

errors with:

Illegal deriving item ‘Constraints’

Which makes sense given http://downloads.haskell.org/~ghc/7.8.3/docs/html/users_guide/deriving.html

I write deriving (Show, Eq, Ord, Data, Typeable) for most of my types. It might be nice to export standard "constraint aliases", i.e. any type of kind * -> Constraint. Given, of course, that the constraints in the constraint tuple are all the right arity, have an empty "minimal complete definition", etc.

Is there any proposal for this? How hard would it be? Are there alternatives?

like image 784
sam boosalis Avatar asked Jan 20 '15 04:01

sam boosalis


1 Answers

There is no proposal for this. It wouldn't be too hard, but I suspect it wouldn't get a lot of traction. Not only could you use template haskell to generate standalone deriving declarations as a comment suggests, but you could macro-expand to your desired clause using CPP if you really want.

like image 159
sclv Avatar answered Nov 15 '22 07:11

sclv