open-adt-1.0: Open algebraic data types.

CopyrightCopyright (c) Jordan Woehr 2018
LicenseBSD
MaintainerJordan Woehr
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Data.OpenADT.TH

Description

This module exports template haskell functions for generating tedious boilerplate.

Synopsis

Documentation

mkVarPattern Source #

Arguments

:: Name

The Name of the type to create patterns for.

-> String

The label in the variant the constructor will have.

-> String

The name of the fixed pattern.

-> String

The name of the unfixed pattern.

-> Q [Dec] 

Create patterns for a variant constructor.

For example, for the type FooF with the constructor FooF':

data FooF a x = FooF' a x
$(mkVarPattern ''FooF "foo" "Foo" "FooF")

A pattern similar to the following will be generated:

pattern FooF :: (OpenAlg r "foo" (FooF a) v) => a -> v -> VarF r v
pattern FooF a v <- VarF (view (Label :: Label "foo") -> Just (FooF' a v))

pattern Foo :: (OpenAlg r "foo" (FooF a) (OpenADT r))
            => a -> OpenADT r -> OpenADT r
  where FooF a v = VarF (IsJust (Label :: Label "foo") (FooF' a v))
pattern Foo  a v = Fix (FooF a v)