data-diverse-1.2.0.1: Extensible records and polymorphic variants.

Safe HaskellSafe
LanguageHaskell2010

Data.Diverse.Reduce

Synopsis

Documentation

type family Reduced handler Source #

Convert something v into r using handlers. This class is required in order to step through all the different types in a variant.

Instances

type Reduced (Switcher c r xs) Source # 
type Reduced (Switcher c r xs) = r
type Reduced (SwitcherN c r n xs) Source # 
type Reduced (SwitcherN c r n xs) = r

class Reduce v handler where Source #

Minimal complete definition

reduce

Methods

reduce :: handler -> v -> Reduced handler Source #

Instances

(Case (c r) ((:) Type x ([] Type)), (~) * r (CaseResult * Type (c r) x)) => Reduce (Which ((:) Type x ([] Type))) (Switcher c r ((:) Type x ([] Type))) Source #

Terminating case of the loop, ensuring that a instance of Case '[] with an empty typelist is not required. You can't reduce zilch

Methods

reduce :: Switcher c r ((Type ': x) [Type]) -> Which ((Type ': x) [Type]) -> Reduced (Switcher c r ((Type ': x) [Type])) Source #

(Case (c r) ((:) Type x ((:) Type x' xs)), Reduce (Which ((:) Type x' xs)) (Switcher c r ((:) Type x' xs)), Reiterate (c r) ((:) Type x ((:) Type x' xs)), (~) * r (CaseResult * Type (c r) x)) => Reduce (Which ((:) Type x ((:) Type x' xs))) (Switcher c r ((:) Type x ((:) Type x' xs))) Source #

trial0 each type in a Which, and either handle the case' with value discovered, or reiterate trying the next type in the type list.

Methods

reduce :: Switcher c r ((Type ': x) ((Type ': x') xs)) -> Which ((Type ': x) ((Type ': x') xs)) -> Reduced (Switcher c r ((Type ': x) ((Type ': x') xs))) Source #

Reduce (Which ([] Type)) (Switcher c r ([] Type)) Source #

Allow 'Which '[]' to be reinterpret'ed or diversifyed into anything else This is safe because Which '[] is uninhabited, and this is already something that can be done with impossible

Methods

reduce :: Switcher c r [Type] -> Which [Type] -> Reduced (Switcher c r [Type]) Source #

(Case (c r n) ((:) Type x ([] Type)), (~) * r (CaseResult * Type (c r n) x)) => Reduce (Which ((:) Type x ([] Type))) (SwitcherN c r n ((:) Type x ([] Type))) Source #

Terminating case of the loop, ensuring that a instance of Case '[] with an empty typelist is not required. You can't reduce zilch

Methods

reduce :: SwitcherN c r n ((Type ': x) [Type]) -> Which ((Type ': x) [Type]) -> Reduced (SwitcherN c r n ((Type ': x) [Type])) Source #

(Case (c r n) ((:) Type x ((:) Type x' xs)), Reduce (Which ((:) Type x' xs)) (SwitcherN c r ((+) n 1) ((:) Type x' xs)), ReiterateN (c r) n ((:) Type x ((:) Type x' xs)), (~) * r (CaseResult * Type (c r n) x)) => Reduce (Which ((:) Type x ((:) Type x' xs))) (SwitcherN c r n ((:) Type x ((:) Type x' xs))) Source #

trial0 each type in a Which, and either handle the case' with value discovered, or reiterateN trying the next type in the type list.

Methods

reduce :: SwitcherN c r n ((Type ': x) ((Type ': x') xs)) -> Which ((Type ': x) ((Type ': x') xs)) -> Reduced (SwitcherN c r n ((Type ': x) ((Type ': x') xs))) Source #