]> gitweb.michael.orlitzky.com - dead/htsn-import.git/commitdiff
Add a Generics module with a generic to_tuple function.
authorMichael Orlitzky <michael@orlitzky.com>
Mon, 29 Dec 2014 20:05:49 +0000 (15:05 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Tue, 30 Dec 2014 00:42:58 +0000 (19:42 -0500)
src/Generics.hs [new file with mode: 0644]

diff --git a/src/Generics.hs b/src/Generics.hs
new file mode 100644 (file)
index 0000000..8e66589
--- /dev/null
@@ -0,0 +1,24 @@
+{-# LANGUAGE DeriveGeneric #-}
+{-# LANGUAGE NoMonomorphismRestriction #-}
+{-# LANGUAGE TypeFamilies #-}
+
+module Generics (
+  Generic(..),
+  to_tuple )
+where
+
+import Generics.SOP ( Code, Generic(..) )
+
+-- | Convert a simple product type into a tuple, generically.
+--
+--   == __Examples__:
+--
+--   >>> import qualified GHC.Generics as GHC ( Generic )
+--   >>> data Foo = Bar Int Int Int Int deriving (Show, GHC.Generic)
+--   >>> instance Generic Foo
+--   >>> let b = Bar 1 2 3 4
+--   >>> to_tuple b :: (Int,Int,Int,Int)
+--   (1,2,3,4)
+--
+to_tuple:: (Generic a, Generic c, Code a ~ Code c) => a -> c
+to_tuple = to . from