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

Language | Haskell2010 |

Provides combinators for currying and uncurrying functions over arbitrary vinyl records.

## Synopsis

- class RecordCurry ts where
- class RecordCurry' ts where
- runcurry :: CurriedF f ts a -> Rec f ts -> a
- runcurry' :: Curried ts a -> Rec Identity ts -> a
- xruncurry :: CurriedX f ts a -> XRec f ts -> a
- runcurryX :: IsoXRec f ts => CurriedX f ts a -> Rec f ts -> a
- runcurryA' :: Applicative f => Curried ts a -> Rec f ts -> f a
- runcurryA :: Applicative f => CurriedF g ts a -> Rec (Compose f g) ts -> f a
- type family Curried ts a where ...
- type family CurriedF (f :: u -> Type) (ts :: [u]) a where ...
- type family CurriedX (f :: u -> Type) (ts :: [u]) a where ...

# Currying

class RecordCurry ts where Source #

rcurry :: (Rec f ts -> a) -> CurriedF f ts a Source #

N-ary version of `curry`

over functorial records.

Example specialized signatures:

rcurry :: (Rec Maybe '[Int, Double] -> Bool) -> Maybe Int -> Maybe Double -> Bool rcurry :: (Rec (Either Int) '[Double, String, ()] -> Int) -> Either Int Double -> Either Int String -> Either Int () -> Int rcurry :: (Rec f '[] -> Bool) -> Bool

#### Instances

RecordCurry ('[] :: [u]) Source # | |

RecordCurry ts => RecordCurry (t ': ts :: [u]) Source # | |

class RecordCurry' ts where Source #

rcurry' :: (Rec Identity ts -> a) -> Curried ts a Source #

N-ary version of `curry`

over pure records.

Example specialized signatures:

rcurry' :: (Rec Identity '[Int, Double] -> Bool) -> Int -> Double -> Bool rcurry' :: (Rec Identity '[Double, String, ()] -> Int) -> Double -> String -> () -> Int rcurry' :: (Rec Identity '[] -> Bool) -> Bool

#### Instances

RecordCurry' ('[] :: [Type]) Source # | |

RecordCurry' ts => RecordCurry' (t ': ts) Source # | |

# Uncurrying

runcurry :: CurriedF f ts a -> Rec f ts -> a Source #

N-ary version of `uncurry`

over functorial records.

Example specialized signatures:

runcurry :: (Maybe Int -> Maybe Double -> String) -> Rec Maybe '[Int, Double] -> String runcurry :: (IO FilePath -> String) -> Rec IO '[FilePath] -> String runcurry :: Int -> Rec f '[] -> Int

runcurry' :: Curried ts a -> Rec Identity ts -> a Source #

N-ary version of `uncurry`

over pure records.

Example specialized signatures:

runcurry' :: (Int -> Double -> String) -> Rec Identity '[Int, Double] -> String runcurry' :: Int -> Rec Identity '[] -> Int

Example usage:

f :: Rec Identity '[Bool, Int, Double] -> Either Int Double f = runcurry' $ b x y -> if b then Left x else Right y

# Applicative Combinators

runcurryA' :: Applicative f => Curried ts a -> Rec f ts -> f a Source #

Lift an N-ary function to work over a record of `Applicative`

computations.

`>>>`

Just 5`runcurryA' (+) (Just 2 :& Just 3 :& RNil)`

`>>>`

Nothing`runcurryA' (+) (Nothing :& Just 3 :& RNil)`

runcurryA :: Applicative f => CurriedF g ts a -> Rec (Compose f g) ts -> f a Source #

Lift an N-ary function over types in `g`

to work over a record of `Compose`

d
`Applicative`

computations. A more general version of `runcurryA'`

.

Example specialized signatures:

runcurryA :: (g x -> g y -> a) -> Rec (Compose Maybe g) '[x, y] -> Maybe a

# Curried Function Types

type family Curried ts a where ... Source #

For the list of types `ts`

,

is a curried function type from
arguments of types in `Curried`

ts a`ts`

to a result of type `a`

.

`>>>`

Curried '[Int, Bool, String] Int :: * = Int -> Bool -> [Char] -> Int`:kind! Curried '[Int, Bool, String] Int`

type family CurriedF (f :: u -> Type) (ts :: [u]) a where ... Source #

For the type-level list `ts`

,

is a curried function type
from arguments of type `CurriedF`

f ts a`f t`

for `t`

in `ts`

, to a result of type `a`

.

`>>>`

CurriedF Maybe '[Int, Bool, String] Int :: * = Maybe Int -> Maybe Bool -> Maybe [Char] -> Int`:kind! CurriedF Maybe '[Int, Bool, String] Int`

type family CurriedX (f :: u -> Type) (ts :: [u]) a where ... Source #

For the type-level list `ts`

,

is a curried function type
from arguments of type `CurriedX`

f ts a`HKD f t`

for `t`

in `ts`

, to a result of type `a`

.

`>>>`

`:set -XTypeOperators`

`>>>`

CurriedX (Maybe :. Identity) '[Int, Bool, String] Int :: * = Maybe Int -> Maybe Bool -> Maybe [Char] -> Int`:kind! CurriedX (Maybe :. Identity) '[Int, Bool, String] Int`