-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | various operations on n-ary tuples via GHC.Generics -- -- Some operations on n-ary tuples, including uncons, cons, -- etc. This package distinguish itself from other packages on tuple -- mainly on the the implementation under the cover. It converts Generic -- datatype into the its representation form, and carries out the -- operations on there. The other point is that this package tends to -- treat non-tuples directly as 1-ary, without need of OneTuple or -- similar intermediate wrapper. @package tuple-ops @version 0.0.0.2 -- | This module defins operations to manipulate the generic representation -- of tuple. module Data.Tuple.Ops.Internal newtype TupleR (f :: [* -> *]) x TupleR :: Tuple (f <&> x) -> TupleR x [unTupleR] :: TupleR x -> Tuple (f <&> x) -- | prove that (a ++ b) & x == a & x ++ b -- & x class AppDistributive (a :: [* -> *]) appDistrWit :: AppDistributive a => (Proxy a, Proxy b, Proxy x) -> Wit (((a ++ b) <&> x) ~ ((a <&> x) ++ (b <&> x))) -- | inductive proof on a case 1. a is [] -- | case 2. a is _ :< _ -- | utility function to call appDistrWit appDistrWitPassArg :: (f :*: g) x -> (Proxy (L f), Proxy (L g), Proxy x) -- | Representation of tuple are shaped in a balanced tree. L -- transforms the tree into a list, for further manipulation. class Linearize (t :: * -> *) where { type family L t :: [* -> *]; } linearize :: Linearize t => t x -> TupleR (L t) x -- | base case. sinleton -- | inductive case. preppend a product with what ever length' :: TupleR a x -> Proxy (Len a) -- | calculate the half -- | calculate the half half :: Proxy n -> Proxy (Half n) -- | take the first n elements from a product class Take (n :: N) (a :: [* -> *]) where { type family T n a :: [* -> *]; } take' :: Take n a => Proxy n -> TupleR a x -> TupleR (T n a) x -- | base case. take one out of singleton -- | inductive case. take (n+1) elements -- | drop the first n elements from a product class Drop (n :: N) (a :: [* -> *]) where { type family D n a :: [* -> *]; } drop' :: Drop n a => Proxy n -> TupleR a x -> TupleR (D n a) x -- | base case. drop one from product -- | inductive case. drop (n+1) elements -- | Normalize converts a linear product back into a balanced tree. class Normalize (a :: [* -> *]) where { type family N a :: * -> *; } normalize :: Normalize a => TupleR a x -> N a x -- | base case. singleton -- | inductive case. product type MetaS = 'MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy -- | utility type function to trim the Rec0 -- | utility type function to trim the S1 -- | utility type function to trim the D1 -- | utility type function to extract the meta information -- | representation of a tuple of arity > 2, in which u -- is of the form _ :*: _ type RepOfTuple c u = C1 ( 'MetaCons c 'PrefixI 'False) u instance Data.Tuple.Ops.Internal.Linearize (GHC.Generics.S1 Data.Tuple.Ops.Internal.MetaS (GHC.Generics.Rec0 t)) instance Data.Tuple.Ops.Internal.Normalize '[GHC.Generics.S1 Data.Tuple.Ops.Internal.MetaS (GHC.Generics.Rec0 t)] instance (Data.Tuple.Ops.Internal.Take (Data.Tuple.Ops.Internal.Half (Type.Family.Nat.N2 Type.Family.Nat.+ Type.Family.Nat.Len c)) (a Type.Family.List.:< (b Type.Family.List.:< c)), Data.Tuple.Ops.Internal.Drop (Data.Tuple.Ops.Internal.Half (Type.Family.Nat.N2 Type.Family.Nat.+ Type.Family.Nat.Len c)) (a Type.Family.List.:< (b Type.Family.List.:< c)), Data.Tuple.Ops.Internal.Normalize (Data.Tuple.Ops.Internal.T (Data.Tuple.Ops.Internal.Half (Type.Family.Nat.N2 Type.Family.Nat.+ Type.Family.Nat.Len c)) (a Type.Family.List.:< (b Type.Family.List.:< c))), Data.Tuple.Ops.Internal.Normalize (Data.Tuple.Ops.Internal.D (Data.Tuple.Ops.Internal.Half (Type.Family.Nat.N2 Type.Family.Nat.+ Type.Family.Nat.Len c)) (a Type.Family.List.:< (b Type.Family.List.:< c)))) => Data.Tuple.Ops.Internal.Normalize (a Type.Family.List.:< (b Type.Family.List.:< c)) instance Data.Tuple.Ops.Internal.Drop 'Type.Family.Nat.Z as instance Data.Tuple.Ops.Internal.Drop n as => Data.Tuple.Ops.Internal.Drop ('Type.Family.Nat.S n) (a : as) instance Data.Tuple.Ops.Internal.Take 'Type.Family.Nat.Z xs instance Data.Tuple.Ops.Internal.Take n as => Data.Tuple.Ops.Internal.Take ('Type.Family.Nat.S n) (a : as) instance (Data.Tuple.Ops.Internal.Linearize v, Data.Tuple.Ops.Internal.Linearize u, Data.Tuple.Ops.Internal.AppDistributive (Data.Tuple.Ops.Internal.L u)) => Data.Tuple.Ops.Internal.Linearize (u GHC.Generics.:*: v) instance Data.Tuple.Ops.Internal.AppDistributive '[] instance Data.Tuple.Ops.Internal.AppDistributive as => Data.Tuple.Ops.Internal.AppDistributive (a Type.Family.List.:< as) -- | This module define cons. Examples are given below: -- --
-- >>> cons (1::Int) () -- 1 ---- --
-- >>> cons (1::Int) 'a' -- (1,'a') ---- --
-- >>> cons (True,'a') "S" -- ((True,'a'),"S") ---- --
-- >>> cons "S" (True,'a')
-- ("S",True,'a')
--
module Data.Tuple.Ops.Cons
-- | cons takes two datatype, and produces a tuple of them. if
-- b is unit, then a is returned. if b is not
-- a tuple, then a pair of (a,b) is returned. otherwise,
-- a is placed in front of b.
cons :: Consable a b c => a -> b -> c
-- | calculate the result type of cons
-- | A constraint on any consable data type, where a and
-- b are the input, and c is the output.
type Consable a b c = (Generic a, Generic b, Generic c, Cons a b ~ c, Rep b ~ D1 (MetaOfD1 (Rep b)) (UnD1 (Rep b)), Rep c ~ D1 (MetaOfD1 (Rep c)) (UnD1 (Rep c)), ConsableR a (UnD1 (Rep b)), ConsR a (UnD1 (Rep b)) b ~ (UnD1 (Rep c)))
instance (GHC.Generics.Generic a, GHC.Generics.Rep a ~ GHC.Generics.D1 (Data.Tuple.Ops.Internal.MetaOfD1 (GHC.Generics.Rep a)) (Data.Tuple.Ops.Internal.UnD1 (GHC.Generics.Rep a))) => Data.Tuple.Ops.Cons.ConsableR a (GHC.Generics.C1 mc GHC.Generics.U1)
instance Data.Tuple.Ops.Cons.ConsableR va (GHC.Generics.C1 mc (GHC.Generics.S1 ms (GHC.Generics.URec b)))
instance Data.Tuple.Ops.Cons.ConsableR va (b0 GHC.Generics.:+: b1)
instance (Data.Tuple.Ops.Internal.Linearize b0, Data.Tuple.Ops.Internal.Linearize b1, Data.Tuple.Ops.Internal.Normalize (GHC.Generics.S1 Data.Tuple.Ops.Internal.MetaS (GHC.Generics.Rec0 va) Type.Family.List.:< (Data.Tuple.Ops.Internal.L b0 Type.Family.List.++ Data.Tuple.Ops.Internal.L b1)), Data.Tuple.Ops.Internal.AppDistributive (Data.Tuple.Ops.Internal.L b0)) => Data.Tuple.Ops.Cons.ConsableR va (Data.Tuple.Ops.Internal.RepOfTuple tcon (b0 GHC.Generics.:*: b1))
-- | This module define uncons. Examples are given below:
--
-- -- >>> uncons (1::Int) -- (1,()) ---- --
-- >>> uncons (1::Int,'a') -- (1,'a') ---- --
-- >>> uncons (True,'a', "S")
-- (True,('a',"S"))
--
module Data.Tuple.Ops.Uncons
-- | uncons takes primitive, pair, tuple, and produces a pair of its
-- first data and the rest elements.
uncons :: Unconsable a b c => a -> (b, c)
-- | calculate the result type of uncons
-- | A constraint on any unconsable data type, where a is
-- the input type, and (b,c) is the output type
type Unconsable a b c = (Generic a, Generic b, Generic c, Uncons a ~ (b, c), Rep a ~ D1 (MetaOfD1 (Rep a)) (UnD1 (Rep a)), Rep b ~ D1 (MetaOfD1 (Rep b)) (UnD1 (Rep b)), Rep c ~ D1 (MetaOfD1 (Rep c)) (UnD1 (Rep c)), UnconsableR (UnD1 (Rep a)), HeadR (UnD1 (Rep a)) ~ (UnD1 (Rep b)), TailR (UnD1 (Rep a)) ~ (UnD1 (Rep c)))
instance Data.Tuple.Ops.Uncons.UnconsableR (GHC.Generics.C1 mc (GHC.Generics.S1 ms (GHC.Generics.URec a)))
instance Data.Tuple.Ops.Uncons.UnconsableR (a GHC.Generics.:+: b)
instance (GHC.Generics.Generic t1, GHC.Generics.Rep t1 ~ GHC.Generics.D1 mt1 ct1, GHC.Generics.Generic t2, GHC.Generics.Rep t2 ~ GHC.Generics.D1 mt2 ct2) => Data.Tuple.Ops.Uncons.UnconsableR (Data.Tuple.Ops.Internal.RepOfTuple "(,)" (GHC.Generics.S1 Data.Tuple.Ops.Internal.MetaS (GHC.Generics.Rec0 t1) GHC.Generics.:*: GHC.Generics.S1 Data.Tuple.Ops.Internal.MetaS (GHC.Generics.Rec0 t2)))
instance (Data.Tuple.Ops.Internal.Linearize (a GHC.Generics.:*: (b GHC.Generics.:*: c)), Data.Tuple.Ops.Internal.L (a GHC.Generics.:*: (b GHC.Generics.:*: c)) ~ (GHC.Generics.S1 Data.Tuple.Ops.Internal.MetaS (GHC.Generics.Rec0 t) : w), GHC.Generics.Generic t, GHC.Generics.Rep t ~ GHC.Generics.D1 hm hc, Data.Tuple.Ops.Internal.Normalize w) => Data.Tuple.Ops.Uncons.UnconsableR (Data.Tuple.Ops.Internal.RepOfTuple tcon (a GHC.Generics.:*: (b GHC.Generics.:*: c)))
-- | This module exports various operations on n-ary tuples
module Data.Tuple.Ops
instance GHC.Generics.Generic GHC.Types.Int
instance GHC.Generics.Generic GHC.Types.Word
instance GHC.Generics.Generic GHC.Types.Char
instance GHC.Generics.Generic GHC.Types.Float
instance GHC.Generics.Generic GHC.Types.Double
instance GHC.Generics.Generic (a, b, c, d, e, f, g, h)
instance GHC.Generics.Generic (a, b, c, d, e, f, g, h, i)
instance GHC.Generics.Generic (a, b, c, d, e, f, g, h, i, j)
instance GHC.Generics.Generic (a, b, c, d, e, f, g, h, i, j, k)
instance GHC.Generics.Generic (a, b, c, d, e, f, g, h, i, j, k, l)
instance GHC.Generics.Generic (a, b, c, d, e, f, g, h, i, j, k, l, m)
instance GHC.Generics.Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
instance GHC.Generics.Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
instance GHC.Generics.Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)