diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2016-09-30 20:15:25 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-09-30 23:23:44 -0400 |
commit | 9e862765ffe161da8a4fd9cd67b0a600874feaa9 (patch) | |
tree | 235c1ba702b0101e1fa6a8fe7f8146e2c7ec9c69 /testsuite/tests/th/T10598_TH.hs | |
parent | b3d55e20d20344bfc09f4ca4a554a819c4ecbfa8 (diff) | |
download | haskell-9e862765ffe161da8a4fd9cd67b0a600874feaa9.tar.gz |
Implement deriving strategies
Allows users to explicitly request which approach to `deriving` to use
via keywords, e.g.,
```
newtype Foo = Foo Bar
deriving Eq
deriving stock Ord
deriving newtype Show
```
Fixes #10598. Updates haddock submodule.
Test Plan: ./validate
Reviewers: hvr, kosmikus, goldfire, alanz, bgamari, simonpj, austin,
erikd, simonmar
Reviewed By: alanz, bgamari, simonpj
Subscribers: thomie, mpickering, oerjan
Differential Revision: https://phabricator.haskell.org/D2280
GHC Trac Issues: #10598
Diffstat (limited to 'testsuite/tests/th/T10598_TH.hs')
-rw-r--r-- | testsuite/tests/th/T10598_TH.hs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/testsuite/tests/th/T10598_TH.hs b/testsuite/tests/th/T10598_TH.hs new file mode 100644 index 0000000000..aab8bb3aa6 --- /dev/null +++ b/testsuite/tests/th/T10598_TH.hs @@ -0,0 +1,42 @@ +{-# 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 |] ]) + [ derivClause (Just Stock) [ [t| Eq |] ] + , derivClause (Just Anyclass) [ [t| C |] ] + , derivClause (Just Newtype) [ [t| Read |] ] ] + , standaloneDerivWithStrategyD (Just Stock) + (cxt []) [t| Ord $(fooType) |] + , standaloneDerivWithStrategyD (Just Anyclass) + (cxt []) [t| D $(fooType) |] + , standaloneDerivWithStrategyD (Just Newtype) + (cxt []) [t| Show $(fooType) |] ]) |