Safe Haskell | None |
---|---|

Language | Haskell2010 |

Convert between functions taking HLists and functions taking many arguments

- class HLengthEq xs n => HCurry' (n :: HNat) f xs r | f xs -> r, r xs -> f, n f -> xs, xs -> n where
- hUncurry :: (ArityRev f n, ArityFwd f n, HCurry' n f xs r) => f -> HList xs -> r
- hCurry :: (ArityRev f n, ArityFwd f n, HCurry' n f xs r) => (HList xs -> r) -> f
- 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
- arityOf :: Arity f n => f -> Proxy n

# 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

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 (,,) (,)`

`>>>`

f :: ... -> ... -> ... -> ... -> ((..., ...), ..., ...)`:t f`

`>>>`

((1,2),3,4)`f 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

`>>>`

'y'`(.) id id id 'y'`

`>>>`

'y'`hCompose id id id '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