Skip to content

wasabi315/coverage-checking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

coverage-check

This repository contains an Agda formalization of one of the coverage checking algorithms for pattern matching presented in the paper "Warnings for pattern matching" by Luc Maranget.

Luc Maranget. 2007. Warnings for pattern matching. J. Funct. Programming 17, 3 (May 2007), 387–421. https://doi.org/10.1017/S0956796807006223

Specifically, we formalize the usefulness checking algorithm $\mathcal{U}_\text{rec}$ presented in Section 3.1 and the exhaustiveness checking algorithm built on top of it. We prove that a pattern matrix is indeed exhaustive if the algorithm returns true, and that there exists a sequence of values that are not covered if the algorithm returns false.

-- type list = Nil | One unit | Cons unit list

P : PatternMatrix (TyData ⟨list⟩ ∷ TyData ⟨list⟩ ∷ [])
P =
  (nil ∷ —   ∷ []) ∷
  (—   ∷ nil ∷ []) ∷ []

-- P is non-exhaustive, witnessed by the following list of patterns
_ : decNonExhaustive P
  ≡ Right (
      ((cons — —  ∷ cons — — ∷ []) ⟨ _ ⟩) ∷
      ((one —     ∷ cons — — ∷ []) ⟨ _ ⟩) ∷
      ((cons — —  ∷ one —    ∷ []) ⟨ _ ⟩) ∷
      ((one —     ∷ one —    ∷ []) ⟨ _ ⟩) ∷ [])
_ = refl

Q : PatternMatrix (TyData ⟨list⟩ ∷ TyData ⟨list⟩ ∷ [])
Q =
  (nil      ∷ —        ∷ []) ∷
  (—        ∷ nil      ∷ []) ∷
  (one —    ∷ —        ∷ []) ∷
  (—        ∷ one —    ∷ []) ∷
  (cons — — ∷ —        ∷ []) ∷
  (—        ∷ cons — — ∷ []) ∷ []

-- Q is exhaustive, so we get a total matching function of type `∀ vs → Match Q vs`
_ : decNonExhaustive Q ≡ Left (Erased (the ( vs  Match Q vs) _))
_ = refl

This formalization is compatible with agda2hs, allowing us to extract readable Haskell code from it!

Tested with Agda v2.8.0, agda-stdlib v2.2, and agda2hs 94e360b.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published