ermine-0.6: Ermine

Copyright(c) Edward Kmett
LicenseBSD3
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Ermine.Syntax.Pattern

Description

 

Synopsis

Documentation

data Pattern t Source

Patterns used by Term

Constructors

SigP t 
WildcardP 
AsP (Pattern t) 
StrictP (Pattern t) 
LazyP (Pattern t) 
LitP !Literal 
ConP !Global [Pattern t] 
TupP [Pattern t] 

Instances

Functor Pattern 
Foldable Pattern 
Traversable Pattern 
Serial1 Pattern 
(Bifunctor p, Choice p, Applicative f) => Tup p f (Pattern t) 
Eq t => Eq (Pattern t) 
Show t => Show (Pattern t) 
Binary t => Binary (Pattern t) 
Serialize t => Serialize (Pattern t) 
Serial a => Serial (Pattern a) 
IsString s => IsString (P (Annot t) s) 

_SigP :: forall t. Prism' (Pattern t) t Source

_WildcardP :: forall t. Prism' (Pattern t) () Source

_AsP :: forall t. Prism' (Pattern t) (Pattern t) Source

_StrictP :: forall t. Prism' (Pattern t) (Pattern t) Source

_LazyP :: forall t. Prism' (Pattern t) (Pattern t) Source

_LitP :: forall t. Prism' (Pattern t) Literal Source

_ConP :: forall t. Prism' (Pattern t) (Global, [Pattern t]) Source

_TupP :: forall t. Prism' (Pattern t) [Pattern t] Source

_ConP' :: Global -> Prism' (Pattern t) [Pattern t] Source

_LitP' :: Literal -> Prism' (Pattern t) [Pattern t] Source

traverseHead :: PatternHead -> Traversal' (Pattern t) [Pattern t] Source

data PatternPath Source

Paths into a pattern tree. These will be used as the bound variables for scopes that have patterns in their binder. No effort has been made to enforce statically that pattern paths used in a given scope correspond only to well-formed paths into the particular tree; it will merely have to be an invariant maintained in the compiler.

LeafPP represents a reference to the variable at a node that binds a variable. For instance, LeafPP is a valid path into SigP. It is also valid for AsP p for all p, because AsP binds a variable. It is invalid for ConP, however.

No effort is made to represent paths with no decision points. This is primarily because it is detrimental to the compilation strategy. AsP, StrictP and LazyP can be thought of as annotations that are not full-fledged patterns in themselves. AsP signals that it is valid to make reference to an entire piece of substructure, while StrictP and LazyP inform the pattern compilation process. But it is unnecessary to distinguish between pointing at an AsP---which is always valid---and pointing at the right portion of an AsP---which is invalid unless the pattern contains redundancies.

Constructors

LeafPP

refer to a variable

FieldPP !Word64 PatternPath

refer to the n-th subpattern of a constructor

ArgPP !Word64 PatternPath

refer to the n-th pattern of many top-level patterns

paths :: Pattern t -> [PatternPath] Source

Returns all the paths pointing to variables in the given pattern, in order from left to right.

manyPaths :: [Pattern t] -> [PatternPath] Source

Returns all the paths pointing to variables in a series of patterns. The list is assumed to contain patterns in left-to-right order, and the resulting list will be in the same order.

data Guarded tm Source

A datatype for representing potentially guarded cases of a function or case body.

Constructors

Unguarded tm 
Guarded [(tm, tm)] 

Instances

Functor Guarded 
Foldable Guarded 
Traversable Guarded 
Serial1 Guarded 
Eq tm => Eq (Guarded tm) 
Ord tm => Ord (Guarded tm) 
Read tm => Read (Guarded tm) 
Show tm => Show (Guarded tm) 
Generic (Guarded tm) 
Binary tm => Binary (Guarded tm) 
Serialize tm => Serialize (Guarded tm) 
Serial v => Serial (Guarded v) 
type Rep (Guarded tm) 

data Alt t f a Source

One alternative of a core expression

Constructors

Alt !(Pattern t) (Guarded (Scope PatternPath f a)) 

Instances

Bound (Alt t) 
Functor f => Functor (Alt t f) 
Foldable f => Foldable (Alt t f) 
Traversable f => Traversable (Alt t f) 
(Serial t, Serial1 f) => Serial1 (Alt t f) 
Monad f => BoundBy (Alt t f) f 
(Eq t, Eq a, Monad f, Eq1 f) => Eq (Alt t f a) 
(Functor f, Show t, Show a, Show1 f) => Show (Alt t f a) 
(Serial t, Serial1 f, Serial a) => Serial (Alt t f a) 

bitraverseAlt :: (Bitraversable k, Applicative f) => (t -> f t') -> (a -> f b) -> Alt t (k t) a -> f (Alt t' (k t') b) Source

Helper function for traversing both sides of an Alt.

serializeAlt3 :: MonadPut m => (t -> m ()) -> (forall a. (a -> m ()) -> f a -> m ()) -> (v -> m ()) -> Alt t f v -> m () Source

deserializeAlt3 :: MonadGet m => m t -> (forall a. m a -> m (f a)) -> m v -> m (Alt t f v) Source