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

Safe HaskellSafe
LanguageHaskell2010

Data.Diverse.Reduce

Synopsis

Documentation

class Reduce v handler xs r where Source #

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

Minimal complete definition

reduce

Methods

reduce :: handler xs r -> v xs -> r Source #

Instances

Case c ((:) Type x ([] Type)) r => Reduce Which (Switch c) ((:) Type x ([] Type)) r Source #

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

Methods

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

(Case c ((:) Type x ((:) Type x' xs)) r, Reduce Which (Switch c) ((:) Type x' xs) r, Reiterate * c ((:) Type x ((:) Type x' xs))) => Reduce Which (Switch c) ((:) Type x ((:) Type x' xs)) r 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. This code will be efficiently compiled into a single case statement in GHC 8.2.1 See http://hsyl20.fr/home/posts/2016-12-12-control-flow-in-haskell-part-2.html

Methods

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

Case (c n) ((:) Type x ([] Type)) r => Reduce Which (SwitchN c n) ((:) Type x ([] Type)) r Source #

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

Methods

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

(Case (c n) ((:) Type x ((:) Type x' xs)) r, Reduce Which (SwitchN c ((+) n 1)) ((:) Type x' xs) r, ReiterateN * c n ((:) Type x ((:) Type x' xs))) => Reduce Which (SwitchN c n) ((:) Type x ((:) Type x' xs)) r 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. This code will be efficiently compiled into a single case statement in GHC 8.2.1 See http://hsyl20.fr/home/posts/2016-12-12-control-flow-in-haskell-part-2.html

Methods

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