row-types-1.0.1.2: Open Records and Variants

Safe Haskell | None
Language | Haskell2010

Data.Row.Switch

Description

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

Synopsis

- class AppliesTo r f x | r x -> f, f r -> x where
  - applyTo :: f -> x -> r
- switch :: forall (v :: Row Type) (r :: Row Type) x. BiForall r v (AppliesTo x) => Var v -> Rec r -> x
- caseon :: forall (v :: Row Type) (r :: Row Type) x. BiForall r v (AppliesTo x) => Rec r -> Var v -> x

# Documentation

class AppliesTo r f x | r x -> f, f r -> x where #

A simple class that we use to provide a constraint for function application.

Methods

applyTo :: f -> x -> r #

#### Instances

Instances details

AppliesTo r (x -> r) x # |
Instance details Defined in Data.Row.Switch Methods applyTo :: (x -> r) -> x -> r #

switch :: forall (v :: Row Type) (r :: Row Type) x. BiForall r v (AppliesTo x) => Var v -> Rec r -> x #

A `Var` and a `Rec` can combine if their rows line up properly. Given a Variant along with 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 :: forall (v :: Row Type) (r :: Row Type) x. BiForall r v (AppliesTo x) => Rec r -> Var v -> x #

The same as `switch` but with the argument order reversed