Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
Signed-off-by: Lîm Tsú-thuàn <inbox@dannypsnl.me>
  • Loading branch information
dannypsnl committed Feb 6, 2025
1 parent 37a26f2 commit dbec0a9
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions pattern-coverage/lib/Algo.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
exception CannotSplit
exception CanSplit
exception FailMatch

type typ = Nat [@printer fun fmt _ -> fprintf fmt "Nat"] [@@deriving show]

type 'a spine =
Expand All @@ -22,7 +18,10 @@ type pattern =
(String.concat " " (List.map show_pattern sp.spine))]
[@@deriving show]

exception NotCover of pattern
exception CannotSplit
exception CanSplit
exception FailMatch
exception NotCovered of pattern

let type_meta : (typ, pattern list) Hashtbl.t = Hashtbl.create 100

Expand All @@ -43,7 +42,7 @@ let rec check_coverage (case : pattern) (patterns : pattern list) : unit =
| CanSplit ->
let cases = split case in
List.iter (fun c -> check_coverage c patterns) cases)
| [] -> raise @@ NotCover case
| [] -> raise @@ NotCovered case

and cover (case : pattern) (pattern : pattern) : unit =
match case, pattern with
Expand All @@ -67,6 +66,6 @@ let%expect_test "" =
; Spine { constructor = "suc"; spine = [ Var ("m1", Nat) ] }
]
with
| NotCover case -> Printf.printf "`%s` is not covered\n" ([%show: pattern] case));
| NotCovered case -> Printf.printf "`%s` is not covered\n" ([%show: pattern] case));
[%expect {| split m |}]
;;

0 comments on commit dbec0a9

Please sign in to comment.