HList-0.5.0.0: Heterogeneous lists

Safe HaskellNone
LanguageHaskell2010

Data.HList.HCurry

Description

Convert between functions taking HLists and functions taking many arguments

Synopsis

Documentation

class HLengthEq xs n => HCurry' (n :: HNat) f xs r | f xs -> r, r xs -> f, n f -> xs, xs -> n where Source #

'curry'/'uncurry' for many arguments and HLists instead of tuples

XXX the last FD xs -> n is needed to make hCompose infer the right types: arguably it shouldn't be needed

Minimal complete definition

hUncurry', hCurry'

Methods

hUncurry' :: Proxy n -> f -> HList xs -> r Source #

hCurry' :: Proxy n -> (HList xs -> r) -> f Source #

Instances

HCurry' HZero b ([] *) b Source # 

Methods

hUncurry' :: Proxy HNat HZero -> b -> HList [*] -> b Source #

hCurry' :: Proxy HNat HZero -> (HList [*] -> b) -> b Source #

HCurry' n b xs r => HCurry' (HSucc n) (x -> b) ((:) * x xs) r Source # 

Methods

hUncurry' :: Proxy HNat (HSucc n) -> (x -> b) -> HList ((* ': x) xs) -> r Source #

hCurry' :: Proxy HNat (HSucc n) -> (HList ((* ': x) xs) -> r) -> x -> b Source #

hUncurry :: (ArityRev f n, ArityFwd f n, HCurry' n f xs r) => f -> HList xs -> r Source #

hCurry :: (ArityRev f n, ArityFwd f n, HCurry' n f xs r) => (HList xs -> r) -> f Source #

Note: with ghc-7.10 the Arity constraint added here does not work properly with hCompose, so it is possible that other uses of hCurry are better served by hCurry' Proxy.

hCompose :: (HSplitAt1 ([] *) n2 xsys xs1 xs2, HCurry' n2 f1 xs1 x, HCurry' n1 b xs2 r, HCurry' n3 f2 xsys r, ArityFwd f1 n2, ArityFwd b n1, ArityRev f1 n2, ArityRev b n1, HAppendList1 * xs1 xs2 xsys) => (x -> b) -> f1 -> f2 Source #

compose two functions that take multiple arguments. The result of the second function is the first argument to the first function. An example is probably clearer:

>>> let f = hCompose (,,) (,)
>>> :t f
f :: ... -> ... -> ... -> ... -> ((..., ...), ..., ...)
>>> f 1 2 3 4
((1,2),3,4)

Note: polymorphism can make it confusing as to how many parameters a function actually takes. For example, the first two ids are id :: (a -> b) -> (a -> b) in

>>> (.) id id id 'y'
'y'
>>> hCompose id id id 'y'
'y'

still typechecks, but in that case hCompose i1 i2 i3 x == i1 ((i2 i3) x) has id with different types than @(.) i1 i2 i3 x == (i1 (i2 i3)) x

Prompted by http://stackoverflow.com/questions/28932054/can-hlistelim-be-composed-with-another-function

arityOf :: Arity f n => f -> Proxy n Source #