invertible-0.1.2: bidirectional arrows, bijective functions, and invariant functors

Safe HaskellTrustworthy
LanguageHaskell2010

Data.Invertible.TH

Description

Convenient construction of bidirectional functions using case-like syntax.

Synopsis

Documentation

biCase :: QuasiQuoter Source #

Construct an expression representing a function bijection based on a set of newline- or semicolon-separated cases. Each case should be two pattern-expressions separated by -. Each pattern-expression is a haskell pattern that can also be interpreted as an expression. You can think of these as symmetric or bidirectional case expressions. The result will be a bijection that is the combination of two lambdas, one with the cases intepreted forward, and one reverse. For example:

newtype T a = C a
biC :: T a <-> a
biC = [biCase| C a <-> a |]
isJust :: Maybe () <-> Bool
isJust = [biCase|
    Just () <-> True
    Nothing <-> False
  |]