vinyl-0.14.3: Extensible Records
Safe HaskellNone
LanguageHaskell2010

Data.Vinyl.Curry

Description

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

Synopsis

Currying

class RecordCurry (ts :: [u]) where Source #

Methods

rcurry :: forall (f :: u -> Type) a. (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

Instances details
RecordCurry ('[] :: [u]) Source # 
Instance details

Defined in Data.Vinyl.Curry

Methods

rcurry :: forall (f :: u -> Type) a. (Rec f ('[] :: [u]) -> a) -> CurriedF f ('[] :: [u]) a Source #

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

Defined in Data.Vinyl.Curry

Methods

rcurry :: forall (f :: u -> Type) a. (Rec f (t ': ts) -> a) -> CurriedF f (t ': ts) a Source #

class RecordCurry' (ts :: [Type]) where Source #

Methods

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

Instances details
RecordCurry' ('[] :: [Type]) Source # 
Instance details

Defined in Data.Vinyl.Curry

Methods

rcurry' :: (Rec Identity ('[] :: [Type]) -> a) -> Curried ('[] :: [Type]) a Source #

RecordCurry' ts => RecordCurry' (t ': ts) Source # 
Instance details

Defined in Data.Vinyl.Curry

Methods

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

Uncurrying

runcurry :: forall {u} (f :: u -> Type) (ts :: [u]) a. 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' :: forall (ts :: [Type]) a. 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

xruncurry :: forall {u} (f :: u -> Type) (ts :: [u]) a. CurriedX f ts a -> XRec f ts -> a Source #

Apply an uncurried function to an XRec.

runcurryX :: forall {u} (f :: u -> Type) (ts :: [u]) a. IsoXRec f ts => CurriedX f ts a -> Rec f ts -> a Source #

Apply an uncurried function to a Rec like runcurry except the function enjoys a type simplified by the XData machinery that strips away type-induced noise like Identity, Compose, and ElField.

Applicative Combinators

runcurryA' :: forall f (ts :: [Type]) a. Applicative f => Curried ts a -> Rec f ts -> f a Source #

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

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

runcurryA :: forall {u} f (g :: u -> Type) (ts :: [u]) a. 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 Composed 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 :: [Type]) a where ... Source #

For the list of types ts, Curried ts a is a curried function type from arguments of types in ts to a result of type a.

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

Equations

Curried ('[] :: [Type]) a = a 
Curried (t ': ts) a = t -> Curried ts a 

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

For the type-level list ts, CurriedF f ts a is a curried function type from arguments of type f t for t in ts, to a result of type a.

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

Equations

CurriedF (f :: u -> Type) ('[] :: [u]) a = a 
CurriedF (f :: u -> Type) (t ': ts :: [u]) a = f t -> CurriedF f ts a 

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

For the type-level list ts, CurriedX f ts a is a curried function type from arguments of type HKD f t for t in ts, to a result of type a.

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

Equations

CurriedX (f :: u -> Type) ('[] :: [u]) a = a 
CurriedX (f :: u -> Type) (t ': ts :: [u]) a = HKD f t -> CurriedX f ts a