Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tuple -- an isomorphism between a product type and a flat tuple #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion generic-lens.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -182,4 +183,3 @@ benchmark generic-lens-bench

default-language: Haskell2010
ghc-options: -Wall

26 changes: 26 additions & 0 deletions src/Data/Generics/Product/Tuple.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{-# LANGUAGE Rank2Types #-}

-----------------------------------------------------------------------------
-- |
-- Module : Data.Generics.Product.Tuple
-- Copyright : (C) 2020 Yuriy Syrovetskiy
-- License : BSD3
-- Maintainer : Csongor Kiss <[email protected]>
-- 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