diff options
author | Ömer Sinan Ağacan <omeragacan@gmail.com> | 2015-09-23 13:19:58 -0500 |
---|---|---|
committer | Austin Seipp <austin@well-typed.com> | 2015-09-23 13:20:52 -0500 |
commit | 5c115236fe795aa01f0c10106f1b1c959486a739 (patch) | |
tree | 36314780a6af4b8906dab5921a621533d37b0bad /testsuite/tests/th/T10891.hs | |
parent | 453cdbfcea6962d0a2b5f532b5cdf53d5f82143d (diff) | |
download | haskell-5c115236fe795aa01f0c10106f1b1c959486a739.tar.gz |
reify associated types when reifying typeclasses
As reported in Trac #10891, Template Haskell's `reify` was not generating Decls
for associated types. This patch fixes that.
Note that even though `reifyTyCon` function used in this patch returns some
type instances, I'm ignoring that.
Here's an example of how associated types are encoded with this patch:
(Simplified representation)
class C a where
type F a :: *
-->
OpenTypeFamilyD "F" ["a"]
With default type instances:
class C a where
type F a :: *
type F a = a
-->
OpenTypeFamilyD "F" ["a"]
TySynInstD "F" (TySynEqn [VarT "a"] "a")
Reviewed By: goldfire
Differential Revision: https://phabricator.haskell.org/D1254
GHC Trac Issues: #10891
Diffstat (limited to 'testsuite/tests/th/T10891.hs')
-rw-r--r-- | testsuite/tests/th/T10891.hs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/testsuite/tests/th/T10891.hs b/testsuite/tests/th/T10891.hs new file mode 100644 index 0000000000..d91caf94f6 --- /dev/null +++ b/testsuite/tests/th/T10891.hs @@ -0,0 +1,39 @@ +{-# LANGUAGE TypeFamilies #-} + +module T10891 where + +import Language.Haskell.TH +import System.IO + +class C a where + f :: a -> Int + +class C' a where + type F a :: * + type F a = a + f' :: a -> Int + +class C'' a where + data Fd a :: * + +instance C' Int where + type F Int = Bool + f' = id + +instance C'' Int where + data Fd Int = B Bool | C Char + +$(return []) + +test :: () +test = + $(let + display :: Name -> Q () + display q = do + i <- reify q + runIO (hPutStrLn stderr (pprint i) >> hFlush stderr) + in do + display ''C + display ''C' + display ''C'' + [| () |]) |