]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blobdiff - src/Generics.hs
Add a Generics module with a generic to_tuple function.
[dead/htsn-import.git] / src / Generics.hs
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