Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- newtype NamedF f (a :: Type) (name :: Symbol) = ArgF (f a)
- pattern Arg :: a -> name :! a
- type (:!) name a = NamedF Identity a name
- type (:?) name a = NamedF Maybe a name
- class InjValue f where
- injValue :: a -> f a
- newtype Param p = Param p
- param :: Name name -> a -> Param (name :! a)
- paramF :: Name name -> f a -> Param (NamedF f a name)
- (!) :: forall p fn fn'. WithParam p fn fn' => fn -> Param p -> fn'
- class WithParam p fn fn' | p fn -> fn' where
- data Defaults = Defaults
- defaults :: Param Defaults
- data Name (name :: Symbol) = Name
- arg :: Name name -> (name :! a) -> a
- argF :: Name name -> NamedF f a name -> f a
- argDef :: Name name -> a -> (name :? a) -> a
- data DApply
- data DFill
- data DPass
- type family Decide (p :: Type) (fn :: Type) :: [Type] where ...
- class WithParam' (ds :: [Type]) p fn fn' | ds p fn -> fn' where
- withParam :: p -> fn -> fn'
Documentation
newtype NamedF f (a :: Type) (name :: Symbol) Source #
Assign a name to a value of type a
wrapped in f
.
#verbose True :: NamedF Identity Bool "verbose"
pattern Arg :: a -> name :! a Source #
Match on an argument without specifying its name. See also: arg
.
type (:?) name a = NamedF Maybe a name Source #
Infix notation for the type of an optional named parameter.
Param p |
class WithParam p fn fn' | p fn -> fn' where Source #
Supply a parameter p
to a function fn
, resulting in fn'
.
For example, when we pass a single named parameter, we get a function without this parameter:
WithParam ("x" :! Char) -- p ("b" :! Bool -> "x" :! Char -> r) -- fn ("b" :! Bool -> r) -- fn'
In case the parameter cannot be supplied, this constraint will become a type error.
Instances
WithParam' (Decide p fn) p fn fn' => WithParam p fn fn' Source # | |
Defined in Named.Internal |
data Name (name :: Symbol) Source #
A proxy for a name, intended for use with -XOverloadedLabels
:
#verbose :: Name "verbose"
arg :: Name name -> (name :! a) -> a Source #
arg
unwraps a named parameter with the specified name. One way to use it is
to match on arguments with -XViewPatterns
:
fn (arg #t -> t) (arg #f -> f) = ...
This way, the names of parameters can be inferred from the patterns: no type
signature for fn
is required. In case a type signature for fn
is
provided, the parameters must come in the same order:
fn :: "t" :! Integer -> "f" :! Integer -> ... fn (arg #t -> t) (arg #f -> f) = ... -- ok fn (arg #f -> f) (arg #t -> t) = ... -- does not typecheck
Instances
(WithParam' ds p r r', fn ~ (p -> r), fn' ~ r') => WithParam' (DApply ': ds) p fn fn' Source # | |
Defined in Named.Internal |
Instances
(WithParam' ds p r r', fn ~ (NamedF f x name -> r), fn' ~ r', f ~ Maybe) => WithParam' (DFill ': ds) p fn fn' Source # | |
Defined in Named.Internal |
Instances
(WithParam' ds p r r', fn ~ (x -> r), fn' ~ (x -> r')) => WithParam' (DPass ': ds) p fn fn' Source # | |
Defined in Named.Internal |
type family Decide (p :: Type) (fn :: Type) :: [Type] where ... Source #
Decide (NamedF f' a' name) (NamedF f a name -> r) = '[DApply] | |
Decide Defaults (NamedF Maybe a name -> r) = DFill ': Decide Defaults r | |
Decide p (x -> r) = DPass ': Decide p r | |
Decide (NamedF f' a' name) t = TypeError ((Text "Named parameter '" :<>: Text name) :<>: Text "' was supplied, but not expected") | |
Decide Defaults t = '[] |
class WithParam' (ds :: [Type]) p fn fn' | ds p fn -> fn' where Source #
Instances
fn ~ fn' => WithParam' ([] :: [Type]) p fn fn' Source # | |
Defined in Named.Internal | |
(WithParam' ds p r r', fn ~ (x -> r), fn' ~ (x -> r')) => WithParam' (DPass ': ds) p fn fn' Source # | |
Defined in Named.Internal | |
(WithParam' ds p r r', fn ~ (NamedF f x name -> r), fn' ~ r', f ~ Maybe) => WithParam' (DFill ': ds) p fn fn' Source # | |
Defined in Named.Internal | |
(WithParam' ds p r r', fn ~ (p -> r), fn' ~ r') => WithParam' (DApply ': ds) p fn fn' Source # | |
Defined in Named.Internal |