tuple-ops-0.0.0.1: various operations on n-ary tuples via GHC.Generics

Copyright(c) 2018 Jiasen Wu
LicenseBSD-style (see the file LICENSE)
MaintainerJiasen Wu <jiasenwu@hotmail.com>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Data.Tuple.Ops.Internal

Description

This module defins operations to manipulate the generic representation of tuple.

Synopsis

Documentation

newtype TupleR (f :: [* -> *]) x Source #

Constructors

TupleR 

Fields

class AppDistributive (a :: [* -> *]) where Source #

prove that (a ++ b) & x == a & x ++ b & x

Minimal complete definition

appDistrWit

Methods

appDistrWit :: (Proxy a, Proxy b, Proxy x) -> Wit (((a ++ b) <&> x) ~ ((a <&> x) ++ (b <&> x))) Source #

Instances

AppDistributive ([] (* -> *)) Source #

inductive proof on a case 1. a is []

Methods

appDistrWit :: (Proxy [* -> *] [* -> *], Proxy [* -> *] b, Proxy * x) -> Wit (([*] ~ (* <&> *) (((* -> *) ++ [* -> *]) b) x) ((* ++ (* <&> *) [* -> *] x) ((* <&> *) b x))) Source #

AppDistributive as => AppDistributive ((:<) (* -> *) a as) Source #

case 2. a is _ :< _

Methods

appDistrWit :: (Proxy [* -> *] (((* -> *) :< a) as), Proxy [* -> *] b, Proxy * x) -> Wit (([*] ~ (* <&> *) (((* -> *) ++ ((* -> *) :< a) as) b) x) ((* ++ (* <&> *) (((* -> *) :< a) as) x) ((* <&> *) b x))) Source #

appDistrWitPassArg :: (f :*: g) x -> (Proxy (L f), Proxy (L g), Proxy x) Source #

utility function to call appDistrWit

class Linearize (t :: * -> *) where Source #

Representation of tuple are shaped in a balanced tree. L transforms the tree into a list, for further manipulation.

Minimal complete definition

linearize

Associated Types

type L t :: [* -> *] Source #

Methods

linearize :: t x -> TupleR (L t) x Source #

Instances

(Linearize v, Linearize u, AppDistributive (L u)) => Linearize ((:*:) * u v) Source #

inductive case. preppend a product with what ever

Associated Types

type L ((* :*: u) v :: * -> *) :: [* -> *] Source #

Methods

linearize :: (* :*: u) v x -> TupleR (L ((* :*: u) v)) x Source #

Linearize (S1 * MetaS (Rec0 * t)) Source #

base case. sinleton

Associated Types

type L (S1 * MetaS (Rec0 * t) :: * -> *) :: [* -> *] Source #

Methods

linearize :: S1 * MetaS (Rec0 * t) x -> TupleR (L (S1 * MetaS (Rec0 * t))) x Source #

length' :: TupleR a x -> Proxy (Len a) Source #

type family Half (a :: N) :: N where ... Source #

calculate the half

Equations

Half (S Z) = Z 
Half (S (S Z)) = S Z 
Half (S (S n)) = S (Half n) 

half :: Proxy n -> Proxy (Half n) Source #

calculate the half

class Take (n :: N) (a :: [* -> *]) where Source #

take the first n elements from a product

Minimal complete definition

take'

Associated Types

type T n a :: [* -> *] Source #

Methods

take' :: Proxy n -> TupleR a x -> TupleR (T n a) x Source #

Instances

Take Z xs Source #

base case. take one out of singleton

Associated Types

type T (Z :: N) (xs :: [* -> *]) :: [* -> *] Source #

Methods

take' :: Proxy N Z -> TupleR xs x -> TupleR (T Z xs) x Source #

Take n as => Take (S n) ((:) (* -> *) a as) Source #

inductive case. take (n+1) elements

Associated Types

type T (S n :: N) (((* -> *) ': a) as :: [* -> *]) :: [* -> *] Source #

Methods

take' :: Proxy N (S n) -> TupleR (((* -> *) ': a) as) x -> TupleR (T (S n) (((* -> *) ': a) as)) x Source #

class Drop (n :: N) (a :: [* -> *]) where Source #

drop the first n elements from a product

Minimal complete definition

drop'

Associated Types

type D n a :: [* -> *] Source #

Methods

drop' :: Proxy n -> TupleR a x -> TupleR (D n a) x Source #

Instances

Drop Z as Source #

base case. drop one from product

Associated Types

type D (Z :: N) (as :: [* -> *]) :: [* -> *] Source #

Methods

drop' :: Proxy N Z -> TupleR as x -> TupleR (D Z as) x Source #

Drop n as => Drop (S n) ((:) (* -> *) a as) Source #

inductive case. drop (n+1) elements

Associated Types

type D (S n :: N) (((* -> *) ': a) as :: [* -> *]) :: [* -> *] Source #

Methods

drop' :: Proxy N (S n) -> TupleR (((* -> *) ': a) as) x -> TupleR (D (S n) (((* -> *) ': a) as)) x Source #

class Normalize (a :: [* -> *]) where Source #

Normalize converts a linear product back into a balanced tree.

Minimal complete definition

normalize

Associated Types

type N a :: * -> * Source #

Methods

normalize :: TupleR a x -> N a x Source #

Instances

Normalize ((:) (* -> *) (S1 * MetaS (Rec0 * t)) ([] (* -> *))) Source #

base case. singleton

Associated Types

type N (((* -> *) ': S1 * MetaS (Rec0 * t)) [* -> *] :: [* -> *]) :: * -> * Source #

Methods

normalize :: TupleR (((* -> *) ': S1 * MetaS (Rec0 * t)) [* -> *]) x -> N (((* -> *) ': S1 * MetaS (Rec0 * t)) [* -> *]) x Source #

(Take (Half ((+) N2 (Len (* -> *) c))) ((:<) (* -> *) a ((:<) (* -> *) b c)), Drop (Half ((+) N2 (Len (* -> *) c))) ((:<) (* -> *) a ((:<) (* -> *) b c)), Normalize (T (Half ((+) N2 (Len (* -> *) c))) ((:<) (* -> *) a ((:<) (* -> *) b c))), Normalize (D (Half ((+) N2 (Len (* -> *) c))) ((:<) (* -> *) a ((:<) (* -> *) b c)))) => Normalize ((:<) (* -> *) a ((:<) (* -> *) b c)) Source #

inductive case. product

Associated Types

type N (((* -> *) :< a) (((* -> *) :< b) c) :: [* -> *]) :: * -> * Source #

Methods

normalize :: TupleR (((* -> *) :< a) (((* -> *) :< b) c)) x -> N (((* -> *) :< a) (((* -> *) :< b) c)) x Source #

type family UnRec0 t where ... Source #

utility type function to trim the Rec0

Equations

UnRec0 (Rec0 t) = t 

type family UnS1 t where ... Source #

utility type function to trim the S1

Equations

UnS1 (S1 _ t) = t 

type family UnD1 t where ... Source #

utility type function to trim the D1

Equations

UnD1 (D1 _ t) = t 

type family MetaOfD1 t where ... Source #

utility type function to extract the meta information

Equations

MetaOfD1 (D1 m _) = m