Safe Haskell | None |
---|---|
Language | Haskell98 |
- compileClauses :: Maybe (QName, Type) -> [Clause] -> TCM CompiledClauses
- data Cl = Cl {
- clPats :: [Arg Pattern]
- clBody :: ClauseBody
- type Cls = [Cl]
- compileWithSplitTree :: (Term -> Term) -> SplitTree -> Cls -> CompiledClauses
- compile :: (Term -> Term) -> Cls -> CompiledClauses
- nextSplit :: Cls -> Maybe (Bool, Arg Int)
- properSplit :: Pattern -> Maybe Bool
- isVar :: Pattern -> Bool
- splitOn :: Bool -> Int -> Cls -> Case Cls
- splitC :: Int -> Cl -> Case Cl
- expandCatchAlls :: Bool -> Int -> Cls -> Cls
- substBody :: Int -> Int -> Term -> ClauseBody -> ClauseBody
Documentation
:: Maybe (QName, Type) | Translate record patterns and coverage check with given type? |
-> [Clause] | |
-> TCM CompiledClauses |
Process function clauses into case tree.
This involves:
1. Coverage checking, generating a split tree.
2. Translation of lhs record patterns into rhs uses of projection.
Update the split tree.
3. Generating a case tree from the split tree.
Phases 1. and 2. are skipped if Nothing
.
Stripped-down version of Clause
used in clause compiler.
compileWithSplitTree :: (Term -> Term) -> SplitTree -> Cls -> CompiledClauses Source
nextSplit :: Cls -> Maybe (Bool, Arg Int) Source
Get the index of the next argument we need to split on. This the number of the first pattern that does a match in the first clause.
properSplit :: Pattern -> Maybe Bool Source
Is is not a variable pattern? And if yes, is it a record pattern?
isVar :: Pattern -> Bool Source
Is this a variable pattern?
Maintain invariant: isVar = isNothing . properSplit
!
splitOn :: Bool -> Int -> Cls -> Case Cls Source
splitOn single n cs
will force expansion of catch-alls
if single
.
expandCatchAlls :: Bool -> Int -> Cls -> Cls Source
Expand catch-alls that appear before actual matches.
Example:
true y x false false y
will expand the catch-all x
to false
.
Catch-alls need also to be expanded if they come before/after a record pattern, otherwise we get into trouble when we want to eliminate splits on records later.
Another example (see Issue 1650):
f (x, (y, z)) true = a
f _ false = b
Split tree:
0 (first argument of f)
- 1 (second component of the pair)
- 3 (last argument of f)
-- true -> a
- false -> b
We would like to get the following case tree:
case 0 of
_,_ -> case 1 of
_,_ -> case 3 of true -> a; false -> b
_ -> case 3 of true -> a; false -> b
_ -> case 3 of true -> a; false -> b
substBody :: Int -> Int -> Term -> ClauseBody -> ClauseBody Source