HList-0.5.3.0: Heterogeneous lists
Safe HaskellSafe-Inferred
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

Methods

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

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

Instances

Instances details
HCurry' 'HZero b ('[] :: [Type]) b Source # 
Instance details

Defined in Data.HList.HCurry

Methods

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

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

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

Defined in Data.HList.HCurry

Methods

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

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

hUncurry :: forall {n :: HNat} {f} {xs :: [Type]} {r}. (HCurry' n f xs r, ArityFwd f n, ArityRev f n) => f -> HList xs -> r Source #

hCurry :: forall {n :: HNat} {f} {xs :: [Type]} {r}. (HCurry' n f xs r, ArityFwd f n, ArityRev f n) => (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 :: forall {f} {n :: HNat} {b} {n :: HNat} {xs :: [Type]} {x} {xs :: [Type]} {r} {n :: HNat} {f} {xsys :: [Type]}. (ArityRev f n, ArityRev b n, ArityFwd f n, ArityFwd b n, HCurry' n f xs x, HCurry' n b xs r, HCurry' n f xsys r, HAppendList1 xs xs xsys, HSplitAt1 ('[] :: [Type]) n xsys xs xs) => (x -> b) -> f -> f 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 #