T10598_TH.hs 1.35 KB
Newer Older
Ryan Scott's avatar
Ryan Scott committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
module T10598_TH where

import Language.Haskell.TH

class C a
instance C Int

class C a => D a
instance D Int

{-
newtype Foo = MkFoo Int
  deriving stock    Eq
  deriving anyclass C
  deriving newtype  Read

deriving stock    instance Ord  Foo
deriving anyclass instance D    Foo
deriving newtype  instance Show Foo
-}

$(do fooDataName  <- newName "Foo"
     mkFooConName <- newName "MkFoo"
     let fooType = conT fooDataName
     sequence [ newtypeD (cxt []) fooDataName [] Nothing
                (normalC mkFooConName
                  [ bangType (bang noSourceUnpackedness noSourceStrictness)
                             [t| Int |] ])
34 35 36 37
                [ derivClause (Just StockStrategy)    [ [t| Eq   |] ]
                , derivClause (Just AnyclassStrategy) [ [t| C    |] ]
                , derivClause (Just NewtypeStrategy)  [ [t| Read |] ] ]
             , standaloneDerivWithStrategyD (Just StockStrategy)
Ryan Scott's avatar
Ryan Scott committed
38
                 (cxt []) [t| Ord $(fooType) |]
39
             , standaloneDerivWithStrategyD (Just AnyclassStrategy)
Ryan Scott's avatar
Ryan Scott committed
40
                 (cxt []) [t| D $(fooType) |]
41
             , standaloneDerivWithStrategyD (Just NewtypeStrategy)
Ryan Scott's avatar
Ryan Scott committed
42
                 (cxt []) [t| Show $(fooType) |] ])