summaryrefslogtreecommitdiff
path: root/docs/users_guide
diff options
context:
space:
mode:
Diffstat (limited to 'docs/users_guide')
-rw-r--r--docs/users_guide/7.12.1-notes.rst3
-rw-r--r--docs/users_guide/glasgow_exts.rst42
2 files changed, 45 insertions, 0 deletions
diff --git a/docs/users_guide/7.12.1-notes.rst b/docs/users_guide/7.12.1-notes.rst
index 188daa9217..dc87c59c9e 100644
--- a/docs/users_guide/7.12.1-notes.rst
+++ b/docs/users_guide/7.12.1-notes.rst
@@ -74,6 +74,9 @@ Language
- Due to a :ghc-ticket:`security issue <10826>`, Safe Haskell now forbids
annotations in programs marked as ``-XSafe``.
+- Generic instances can be derived for data types whose constructors have
+ arguments with certain unlifted types. See :ref:`generic-programming` for
+ more details.
Compiler
~~~~~~~~
diff --git a/docs/users_guide/glasgow_exts.rst b/docs/users_guide/glasgow_exts.rst
index e2dd28e9f7..bc9e0233f3 100644
--- a/docs/users_guide/glasgow_exts.rst
+++ b/docs/users_guide/glasgow_exts.rst
@@ -12004,6 +12004,48 @@ we show generic serialization:
Typically this class will not be exported, as it only makes sense to
have instances for the representation types.
+Unlifted representation types
+-----------------------------
+
+The data family ``URec`` is provided to enable generic programming over
+datatypes with certain unlifted arguments. There are six instances corresponding
+to common unlifted types: ::
+
+ data family URec a p
+
+ data instance URec (Ptr ()) p = UAddr { uAddr# :: Addr# }
+ data instance URec Char p = UChar { uChar# :: Char# }
+ data instance URec Double p = UDouble { uDouble# :: Double# }
+ data instance URec Int p = UInt { uInt# :: Int# }
+ data instance URec Float p = UFloat { uFloat# :: Float# }
+ data instance URec Word p = UWord { uWord# :: Word# }
+
+Six type synonyms are provided for convenience: ::
+
+ type UAddr = URec (Ptr ())
+ type UChar = URec Char
+ type UDouble = URec Double
+ type UFloat = URec Float
+ type UInt = URec Int
+ type UWord = URec Word
+
+As an example, this data declaration: ::
+
+ data IntHash = IntHash Int#
+ deriving Generic
+
+results in the following ``Generic`` instance: ::
+
+ instance Generic IntHash where
+ type Rep IntHash =
+ D1 D1IntHash
+ (C1 C1_0IntHash
+ (S1 NoSelector UInt))
+
+A user could provide, for example, a ``GSerialize UInt`` instance so that a
+``Serialize IntHash`` instance could be easily defined in terms of
+``GSerialize``.
+
Generic defaults
----------------