Safe Haskell | None |
---|---|
Language | Haskell2010 |
FreeC.Pass.CompletePatternPass
Description
This module contains a compiler pass that checks if all function declarations have complete pattern matching. A pattern is complete if there is exactly one case alternative for each constructor of the corresponding type.
Examples
Example 1
The module consisting of the following declarations
data Maybe a = Just a | Nothing fromJust :: Maybe a -> a fromJust @a (x :: Maybe a) = case (x :: Maybe a) of {Just a -> a}
should not pass the check because the case
expression is missing an
alternative for the constructor Nothing
.
Example 2
The following declaration with redundant alternatives
redundant :: Just Bool -> Just Bool redundant (on :: Just Bool) = case (on :: Just Bool) of { Just a -> Just False; Nothing -> Nothing; Just b -> Just True }
should not pass the check because the case
expression has two
alternatives for the constructor Just
.
Example 3
The following declaration where the scrutinee is a function
case_id = case \x -> x of
should not pass the check because functions are not permitted as scrutinees.
Specification
Preconditions
The type of all checked expressions has to be annotated. The environment has to contain the names of all constructors for all used data types. Additionally, the environment should contain entries for all used type synonyms.
Translation
This pass only performs a check and therefore does not change the module.
Postconditions
All case expressions are guaranteed to have complete pattern matching.
Error cases
A fatal error is reported if an incomplete case expression is found.
Synopsis
Documentation
completePatternPass :: Pass Module Module Source #
Checks that all functions of a given module have complete pattern matching.
The pattern matching for a function is complete if for each case
expression there exists exactly one case alternative for each constructor
of the corresponding type.
checkPatternFuncDecl :: FuncDecl -> Converter () Source #
Checks a function declaration for incomplete patterns.