From 689fba11adcc3f72d348ae914074052b991b6f63 Mon Sep 17 00:00:00 2001 From: Yuriy Syrovetskiy Date: Tue, 4 Feb 2020 18:59:28 +0300 Subject: [PATCH] Add tuple -- an isomorphism between a product type and a flat tuple --- generic-lens.cabal | 2 +- src/Data/Generics/Product/Tuple.hs | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/Data/Generics/Product/Tuple.hs diff --git a/generic-lens.cabal b/generic-lens.cabal index 632dcc4..4fb7d58 100644 --- a/generic-lens.cabal +++ b/generic-lens.cabal @@ -30,6 +30,7 @@ library , Data.Generics.Product.Param , Data.Generics.Product.Positions , Data.Generics.Product.Subtype + , Data.Generics.Product.Tuple , Data.Generics.Product.Typed , Data.Generics.Product.Types , Data.Generics.Product.Constraints @@ -182,4 +183,3 @@ benchmark generic-lens-bench default-language: Haskell2010 ghc-options: -Wall - diff --git a/src/Data/Generics/Product/Tuple.hs b/src/Data/Generics/Product/Tuple.hs new file mode 100644 index 0000000..3cb9921 --- /dev/null +++ b/src/Data/Generics/Product/Tuple.hs @@ -0,0 +1,26 @@ +{-# LANGUAGE Rank2Types #-} + +----------------------------------------------------------------------------- +-- | +-- Module : Data.Generics.Product.Tuple +-- Copyright : (C) 2020 Yuriy Syrovetskiy +-- License : BSD3 +-- Maintainer : Csongor Kiss +-- Stability : experimental +-- Portability : non-portable +-- +-- Derive an isomorphism between a product type and a flat tuple. +-- +----------------------------------------------------------------------------- + +module Data.Generics.Product.Tuple (tuple) where + +import Data.GenericLens.Internal (tupled, ListTuple) +import Data.Generics.Internal.Profunctor.Iso (iso2isovl) +import Data.Generics.Product.HList (IsList (list)) +import GHC.Generics (Generic, Rep) + +import qualified Data.Generics.Internal.VL.Iso as VL + +tuple :: (IsList f f as as, ListTuple t as) => VL.Iso' f t +tuple = list . iso2isovl tupled