Safe Haskell | None |
---|---|
Language | Haskell2010 |
Data.TypeRep.VarArg
Description
Utilities for polyvariadic functions
- newtype Res a = Res a
- type family ToRes a
- type family FromRes a
- data Arity a where
- class VarArg t where
- arity :: VarArg t => TypeRep t a -> Arity (ToRes a)
- fromResInv :: VarArg t => TypeRep t a -> Dict (FromRes (ToRes a) ~ a)
- type NonFunction a = ToRes a ~ Res a
- nonFunction :: (VarArg t, MonadError String m) => TypeRep t a -> m (Dict (NonFunction a))
- type family FunM m a
- liftMonadic :: forall t a m. (VarArg t, Monad m) => Proxy m -> TypeRep t a -> a -> FunM m (ToRes a)
- runMonadic :: forall t a m. VarArg t => (forall a. m a -> a) -> TypeRep t a -> FunM m (ToRes a) -> a
- compMonadic :: forall t a m1 m2. VarArg t => (forall a. m1 a -> m2 a) -> TypeRep t a -> FunM m1 (ToRes a) -> FunM m2 (ToRes a)
- type family FunM2 m a
- liftMonadic2 :: forall t a m. (VarArg t, Monad m) => Proxy m -> TypeRep t a -> a -> FunM2 m (ToRes a)
Working with polyvariadic functions
Put a Res
marker at the result type of a function
ToRes (a -> b -> ... -> x) = a -> b -> ... -> Res x
Remove the Res
marker at the result type of a function
FromRes (a -> b -> ... -> Res x) = a -> b -> ... -> x
type NonFunction a = ToRes a ~ Res a Source
nonFunction :: (VarArg t, MonadError String m) => TypeRep t a -> m (Dict (NonFunction a)) Source
Attempt to prove that a type is not a function type
N-ary monadic functions
liftMonadic :: forall t a m. (VarArg t, Monad m) => Proxy m -> TypeRep t a -> a -> FunM m (ToRes a) Source
Lift a function to a similar function with monadic result type
liftMonadic _ _ f = \a b ... x -> return (f a b ... x)
runMonadic :: forall t a m. VarArg t => (forall a. m a -> a) -> TypeRep t a -> FunM m (ToRes a) -> a Source
Run the result of a monadic function
runMonadic run _ f = \a b ... x -> run (f a b ... x)
compMonadic :: forall t a m1 m2. VarArg t => (forall a. m1 a -> m2 a) -> TypeRep t a -> FunM m1 (ToRes a) -> FunM m2 (ToRes a) Source
Compose a function with an N-ary monadic function
compMonadic f _ g = \a b ... x -> f (g a b ... x)