summaryrefslogtreecommitdiff
path: root/testsuite/tests/generics/GShow/Main.hs
diff options
context:
space:
mode:
authorRyanGlScott <ryan.gl.scott@gmail.com>2015-10-03 19:21:37 +0200
committerBen Gamari <ben@smart-cactus.org>2015-10-03 20:03:15 +0200
commit6cde981a8788b225819be28659caddc35b77972d (patch)
treef78cd8be5a0549a654e523345bbde48a80493120 /testsuite/tests/generics/GShow/Main.hs
parenta96f1acc59f425062e6192b4cd2a19e1ef987f4a (diff)
downloadhaskell-6cde981a8788b225819be28659caddc35b77972d.tar.gz
Make GHC generics capable of handling unboxed types
This adds a data family (`URec`) and six data family instances (`UAddr`, `UChar`, `UDouble`, `UFloat`, `UInt`, and `UWord`) which a `deriving Generic(1)` clause will generate if it sees `Addr#`, `Char#`, `Double#`, `Float#`, `Int#`, or `Word#`, respectively. The programmer can then provide instances for these data family instances to provide custom implementations for unboxed types, similar to how derived `Eq`, `Ord`, and `Show` instances currently special-case unboxed types. Fixes #10868. Test Plan: ./validate Reviewers: goldfire, dreixel, bgamari, austin, hvr, kosmikus Reviewed By: dreixel, kosmikus Subscribers: simonpj, thomie Differential Revision: https://phabricator.haskell.org/D1239 GHC Trac Issues: #10868
Diffstat (limited to 'testsuite/tests/generics/GShow/Main.hs')
-rw-r--r--testsuite/tests/generics/GShow/Main.hs10
1 files changed, 8 insertions, 2 deletions
diff --git a/testsuite/tests/generics/GShow/Main.hs b/testsuite/tests/generics/GShow/Main.hs
index 81768ed647..952602e54d 100644
--- a/testsuite/tests/generics/GShow/Main.hs
+++ b/testsuite/tests/generics/GShow/Main.hs
@@ -1,12 +1,14 @@
-{-# LANGUAGE DeriveGeneric #-}
+{-# LANGUAGE DeriveGeneric, MagicHash #-}
module Main where
+import GHC.Exts
import GHC.Generics hiding (C, D)
import GShow
-- We should be able to generate a generic representation for these types
data D a = D0 | D1 { d11 :: a, d12 :: (D a) } deriving Generic
+data U a = U a Char# Double# Float# Int# Word# deriving Generic
-- Example values
d0 :: D Char
@@ -16,8 +18,12 @@ d1 = D1 (Just 'p') D0
d2 :: D (Int,Float)
d2 = D1 (3,0.14) D0
+u0 :: U Int
+u0 = U 1 '1'# -1.0## -1.0# -1# 1##
+
-- Generic instances
instance (GShow a) => GShow (D a)
+instance (GShow a) => GShow (U a)
-- Tests
-main = mapM_ putStrLn [gshow d0, gshow d1, gshow d2]
+main = mapM_ putStrLn [gshow d0, gshow d1, gshow d2, gshow u0]