module Data.HList.HCurry where
import Data.HList.FakePrelude
import Data.HList.HList
import Data.HList.TypeEqO ()
class HLengthEq xs n => HCurry' (n :: HNat) f xs r
| f xs -> r, r xs -> f, n f -> xs, xs -> n where
hUncurry' :: Proxy n -> f -> HList xs -> r
hCurry' :: Proxy n -> (HList xs -> r) -> f
instance HCurry' HZero b '[] b where
hUncurry' :: Proxy 'HZero -> b -> HList '[] -> b
hUncurry' Proxy 'HZero
_ b
b HList '[]
_ = b
b
hCurry' :: Proxy 'HZero -> (HList '[] -> b) -> b
hCurry' Proxy 'HZero
_ HList '[] -> b
f = HList '[] -> b
f HList '[]
HNil
instance (HCurry' n b xs r) => HCurry' (HSucc n) (x -> b) (x ': xs) r where
hUncurry' :: Proxy ('HSucc n) -> (x -> b) -> HList (x : xs) -> r
hUncurry' Proxy ('HSucc n)
n x -> b
f (HCons x xs) = Proxy n -> b -> HList xs -> r
forall (n :: HNat) f (xs :: [*]) r.
HCurry' n f xs r =>
Proxy n -> f -> HList xs -> r
hUncurry' (Proxy ('HSucc n) -> Proxy n
forall (n :: HNat). Proxy ('HSucc n) -> Proxy n
hPred Proxy ('HSucc n)
n) (x -> b
f x
x) HList xs
xs
hCurry' :: Proxy ('HSucc n) -> (HList (x : xs) -> r) -> x -> b
hCurry' Proxy ('HSucc n)
n HList (x : xs) -> r
f x
x = Proxy n -> (HList xs -> r) -> b
forall (n :: HNat) f (xs :: [*]) r.
HCurry' n f xs r =>
Proxy n -> (HList xs -> r) -> f
hCurry' (Proxy ('HSucc n) -> Proxy n
forall (n :: HNat). Proxy ('HSucc n) -> Proxy n
hPred Proxy ('HSucc n)
n) (HList (x : xs) -> r
f (HList (x : xs) -> r)
-> (HList xs -> HList (x : xs)) -> HList xs -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> HList xs -> HList (x : xs)
forall x (xs :: [*]). x -> HList xs -> HList (x : xs)
HCons x
x)
hUncurry :: f -> HList xs -> r
hUncurry f
f = Proxy n -> f -> HList xs -> r
forall (n :: HNat) f (xs :: [*]) r.
HCurry' n f xs r =>
Proxy n -> f -> HList xs -> r
hUncurry' (f -> Proxy n
forall f (n :: HNat). Arity f n => f -> Proxy n
arityOf f
f) f
f
hCurry :: (HList xs -> r) -> f
hCurry HList xs -> r
f = let f' :: f
f' = Proxy n -> (HList xs -> r) -> f
forall (n :: HNat) f (xs :: [*]) r.
HCurry' n f xs r =>
Proxy n -> (HList xs -> r) -> f
hCurry' (f -> Proxy n
forall f (n :: HNat). Arity f n => f -> Proxy n
arityOf f
f') HList xs -> r
f
in f
f'
hCompose :: (x -> b) -> f -> f
hCompose x -> b
f f
g = Proxy n -> (HList xsys -> r) -> f
forall (n :: HNat) f (xs :: [*]) r.
HCurry' n f xs r =>
Proxy n -> (HList xs -> r) -> f
hCurry' Proxy n
forall k (t :: k). Proxy t
Proxy ((HList xsys -> r) -> f) -> (HList xsys -> r) -> f
forall a b. (a -> b) -> a -> b
$ \HList xsys
xs -> case Proxy n -> HList xsys -> (HList xs, HList xs)
forall (n :: HNat) (xsys :: [*]) (xs :: [*]) (ys :: [*]).
HSplitAt n xsys xs ys =>
Proxy n -> HList xsys -> (HList xs, HList ys)
hSplitAt Proxy n
forall k (t :: k). Proxy t
Proxy HList xsys
xs of
(HList xs
xg,HList xs
xf) -> (x -> b) -> HList (x : xs) -> r
forall (n :: HNat) f (xs :: [*]) r.
(HCurry' n f xs r, ArityFwd f n, ArityRev f n) =>
f -> HList xs -> r
hUncurry x -> b
f (f -> HList xs -> x
forall (n :: HNat) f (xs :: [*]) r.
(HCurry' n f xs r, ArityFwd f n, ArityRev f n) =>
f -> HList xs -> r
hUncurry f
g HList xs
xg x -> HList xs -> HList (x : xs)
forall x (xs :: [*]). x -> HList xs -> HList (x : xs)
`HCons` HList xs
xf)
arityOf :: Arity f n => f -> Proxy n
arityOf :: f -> Proxy n
arityOf f
_ = Proxy n
forall k (t :: k). Proxy t
Proxy