From d3a9a422741104a526dedfbe4032d81c728cdbe1 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Mon, 29 Dec 2014 15:05:49 -0500 Subject: [PATCH] Add a Generics module with a generic to_tuple function. --- src/Generics.hs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/Generics.hs diff --git a/src/Generics.hs b/src/Generics.hs new file mode 100644 index 0000000..8e66589 --- /dev/null +++ b/src/Generics.hs @@ -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 -- 2.43.2