template-haskell-natural-1.0.0.0
Safe HaskellNone
LanguageHaskell2010

Language.Haskell.TH.Natural.Syntax.Case

Description

Builder for a case expression. You can find an example usage here.

Synopsis

Builder

case_ :: GenExpr b => b -> CaseExprBuilder () -> Q CaseE Source #

takes an expression to pattern match on and a CaseExprBuilder to produce a case expression

type CaseExprBuilder = ConstBuilder CaseE Source #

A builder for the matches and branches in a case expression

Match

matchConst :: (GenPat b1, GenExpr b2) => b1 -> b2 -> CaseExprBuilder () Source #

Match on a constant expression (e.g. a literal). The second argument is the body of the match.

matchWild :: GenExpr b => b -> CaseExprBuilder () Source #

Match using a wildcard pattern. The argument is the body of the match.

matchList :: GenExpr b => Int -> ([Exp] -> b) -> CaseExprBuilder () Source #

Match on a list of the given size. The second argument is the body of the match, and its input is a list of VarE bound to each item in the list

matchCon :: Name -> ConMatchBuilder 'Empty 'Ready () -> CaseExprBuilder () Source #

Match using a constructor. The ConMatchBuilder allow deconstructing and accessing the fields of the constructor

Pattern match on constructors

Type

type ConMatchBuilder = Builder ConMatchBuilderState Source #

Builds a case match for a predefined constructor (see matchCon)

class ConPatternBuilder (m :: Type -> Type) where Source #

Methods

setFieldPattern :: Int -> Pat -> m () Source #

Instances

Instances details
ConPatternBuilder PatternBuilder Source # 
Instance details

Defined in Language.Haskell.TH.Natural.Syntax.Case

ConPatternBuilder (ConMatchBuilder step step) Source # 
Instance details

Defined in Language.Haskell.TH.Natural.Syntax.Case

Methods

setFieldPattern :: Int -> Pat -> ConMatchBuilder step step () Source #

field :: forall {k} s (step :: k) a. ConPatternBuilder (Builder s step step) => Int -> Pattern a -> Builder s step step a Source #

In a pattern that deconstruct the value, this binds the field at the given index using the Pattern

body :: GenExpr b => b -> ConMatchBuilder 'Empty 'Ready () Source #

Sets the body of the match

Pattern Builder

Types

Functions

var :: Pattern Exp Source #

Allow binding a constructor's field to a name

constant :: GenPat b => b -> Pattern () Source #

Pattern-match a constructor's field to a constant (e.g. a literal)

constructor :: Name -> (Int -> PatternBuilder a) -> Pattern a Source #

Pattern-match a constructor's field On a nested constructor

The second argument is invoked for each field in the constructor

Reexports