named-0.2.0.0: Named parameters (keyword arguments) for Haskell

Safe HaskellNone
LanguageHaskell2010

Named.Internal

Synopsis

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"

Constructors

ArgF (f a)

Match on an F-argument without specifying its name. See also: argF.

Instances
(name ~ name', a ~ a', InjValue f) => IsLabel name (a -> NamedF f a' name') Source # 
Instance details

Defined in Named.Internal

Methods

fromLabel :: a -> NamedF f a' name' #

pattern Arg :: a -> name :! a Source #

Match on an argument without specifying its name. See also: arg.

type (:!) name a = NamedF Identity a name Source #

Infix notation for the type of a named parameter.

type (:?) name a = NamedF Maybe a name Source #

Infix notation for the type of an optional named parameter.

class InjValue f where Source #

Minimal complete definition

injValue

Methods

injValue :: a -> f a Source #

Instances
InjValue Maybe Source # 
Instance details

Defined in Named.Internal

Methods

injValue :: a -> Maybe a Source #

InjValue Identity Source # 
Instance details

Defined in Named.Internal

Methods

injValue :: a -> Identity a Source #

newtype Param p Source #

Constructors

Param p 
Instances
(p ~ NamedF f a name, InjValue f) => IsLabel name (a -> Param p) Source # 
Instance details

Defined in Named.Internal

Methods

fromLabel :: a -> Param p #

(!) :: forall p fn fn'. WithParam p fn fn' => fn -> Param p -> fn' infixl 9 Source #

Supply a parameter to a function:

function ! #param_name value
function ! #x 7 ! #y 42 ! defaults

This is an infix version of with.

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.

Minimal complete definition

with

Methods

with :: Param p -> fn -> fn' Source #

Supply a parameter to a function:

 with (#param_name value) function
 
 with defaults function
 

This is a prefix version of the (!) operator.

Instances
WithParam' (Decide p fn) p fn fn' => WithParam p fn fn' Source # 
Instance details

Defined in Named.Internal

Methods

with :: Param p -> fn -> fn' Source #

data Defaults Source #

Constructors

Defaults 

defaults :: Param Defaults Source #

Passing defaults to a function fills all unspecified optional parameters with Nothing:

fn            :: "b" :! Bool -> "x" :? Char -> Int -> IO ()
fn ! defaults :: "b" :! Bool ->                Int -> IO ()

data Name (name :: Symbol) Source #

A proxy for a name, intended for use with -XOverloadedLabels:

#verbose :: Name "verbose"

Constructors

Name 
Instances
name ~ name' => IsLabel name' (Name name) Source # 
Instance details

Defined in Named.Internal

Methods

fromLabel :: Name name #

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

argF :: Name name -> NamedF f a name -> f a Source #

argF is similar to arg: it unwraps a named parameter with the specified name. The difference is that the result of argF is inside an arity wrapper, which is Identity for normal parameters and Maybe for optional parameters.

argDef :: Name name -> a -> (name :? a) -> a Source #

A variation of arg for optional arguments. Requires a default value to handle the case when the optional argument was omitted:

fn (argDef #answer 42 -> ans) = ...

In case you want to get a value wrapped in Maybe instead, use argF or ArgF.

data DApply Source #

Instances
(WithParam' ds p r r', fn ~ (p -> r), fn' ~ r') => WithParam' (DApply ': ds) p fn fn' Source # 
Instance details

Defined in Named.Internal

Methods

withParam :: p -> fn -> fn' Source #

data DFill Source #

Instances
(WithParam' ds p r r', fn ~ (NamedF f x name -> r), fn' ~ r', f ~ Maybe) => WithParam' (DFill ': ds) p fn fn' Source # 
Instance details

Defined in Named.Internal

Methods

withParam :: p -> fn -> fn' Source #

data DPass Source #

Instances
(WithParam' ds p r r', fn ~ (x -> r), fn' ~ (x -> r')) => WithParam' (DPass ': ds) p fn fn' Source # 
Instance details

Defined in Named.Internal

Methods

withParam :: p -> fn -> fn' Source #

type family Decide (p :: Type) (fn :: Type) :: [Type] where ... Source #

Equations

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 #

Minimal complete definition

withParam

Methods

withParam :: p -> fn -> fn' Source #

Instances
fn ~ fn' => WithParam' ([] :: [Type]) p fn fn' Source # 
Instance details

Defined in Named.Internal

Methods

withParam :: p -> fn -> fn' Source #

(WithParam' ds p r r', fn ~ (x -> r), fn' ~ (x -> r')) => WithParam' (DPass ': ds) p fn fn' Source # 
Instance details

Defined in Named.Internal

Methods

withParam :: p -> fn -> fn' Source #

(WithParam' ds p r r', fn ~ (NamedF f x name -> r), fn' ~ r', f ~ Maybe) => WithParam' (DFill ': ds) p fn fn' Source # 
Instance details

Defined in Named.Internal

Methods

withParam :: p -> fn -> fn' Source #

(WithParam' ds p r r', fn ~ (p -> r), fn' ~ r') => WithParam' (DApply ': ds) p fn fn' Source # 
Instance details

Defined in Named.Internal

Methods

withParam :: p -> fn -> fn' Source #