row-types-0.2.2.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 * ((:) (LT *) ((:->) * l a) v)) (R * ((:) (LT *) ((:->) * l (a -> b)) r)) b Source # 

Methods

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

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

Switch (R * ([] (LT *))) (R * ([] (LT *))) x Source # 

Methods

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

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