row-types-0.3.1.0: Open Records and Variants

Safe HaskellNone
LanguageHaskell98

Data.Row.Switch

Description

This module provides the ability to discharge a polymorphic variant using a record that has matching fields.

Synopsis

Documentation

class Switch (v :: Row *) (r :: Row *) x | v x -> r, r x -> v where Source #

A Var and a Rec can combine if their rows line up properly.

Minimal complete definition

switch | caseon

Methods

switch :: Var v -> Rec r -> x Source #

Given a Variant and a Record of functions from each possible value of the variant to a single output type, apply the correct function to the value in the variant.

caseon :: Rec r -> Var v -> x Source #

The same as switch but with the argument order reversed

Instances
(KnownSymbol l, Switch (R v) (R r) b) => Switch (R ((l :-> a) ': v)) (R ((l :-> (a -> b)) ': r)) b Source # 
Instance details

Defined in Data.Row.Switch

Methods

switch :: Var (R ((l :-> a) ': v)) -> Rec (R ((l :-> (a -> b)) ': r)) -> b Source #

caseon :: Rec (R ((l :-> (a -> b)) ': r)) -> Var (R ((l :-> a) ': v)) -> b Source #

Switch (R ([] :: [LT Type])) (R ([] :: [LT Type])) x Source # 
Instance details

Defined in Data.Row.Switch

Methods

switch :: Var (R []) -> Rec (R []) -> x Source #

caseon :: Rec (R []) -> Var (R []) -> x Source #