Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Pattern matcher no more supposed to warn on non exhaustive patterns ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Dan Grossman <danieljg@c...>
Subject: Re: [Caml-list] Pattern matcher no more supposed to warn on non exhaustive patterns ?

So long as the issue of when clauses has come up, I'll also point out that
the pattern-compiler essentially assumes that when clauses are pure.  I'm
not complaining because I consider it poor style to violate this assumption,
but I've never heard it discussed anywhere.

For the program below, ocamlopt version 3.00 produces a program that prints
1314.

--Dan

-- 
| Dan Grossman     www.cs.cornell.edu/home/danieljg H:607 256 0724 |
| 5157 Upson Hall  danieljg@cs.cornell.edu          O:607 255 9834 |

===============

type y = {mutable c:bool}
type x = {a:y; b:y}

let f1 (v:x) = 
  match v with
    {a = _; b = _} when (v.a.c <- false; v.b.c <- false; false) -> 0
  | {a = {c=false}; b = {c=false}} -> 1
  | {a = {c=false}; b = {c=true}}  -> 2
  | {a = {c=true};  b = {c=false}} -> 3
  | {a = {c=true};  b = {c=true}}  -> 4

let f2 (v:x) = 
  match v with
    {a = {c=true}; b = _} when (v.a.c <- false; v.b.c <- false; false) -> 0
  | {a = {c=false}; b = {c=false}} -> 1
  | {a = {c=false}; b = {c=true}}  -> 2
  | {a = {c=true};  b = {c=false}} -> 3
  | {a = {c=true};  b = {c=true}}  -> 4

let f3 (v:x) = 
  match v with
    {a = _; b = {c=true}} when (v.a.c <- false; v.b.c <- false; false) -> 0
  | {a = {c=false}; b = {c=false}} -> 1
  | {a = {c=false}; b = {c=true}}  -> 2
  | {a = {c=true};  b = {c=false}} -> 3
  | {a = {c=true};  b = {c=true}}  -> 4

let f4 (v:x) = 
  match v with
    {a = {c=true}; b={c=true}} when (v.a.c <- false; v.b.c <- false; false)
-> 0
  | {a = {c=false}; b = {c=false}} -> 1
  | {a = {c=false}; b = {c=true}}  -> 2
  | {a = {c=true};  b = {c=false}} -> 3
  | {a = {c=true};  b = {c=true}}  -> 4

let main () =
  let v1:x = {a = {c=true}; b = {c=true}} in
  let v2:x = {a = {c=true}; b = {c=true}} in
  let v3:x = {a = {c=true}; b = {c=true}} in
  let v4:x = {a = {c=true}; b = {c=true}} in
  print_int (f1 v1);
  print_int (f2 v2);
  print_int (f3 v3);
  print_int (f4 v4)

let _ = main ()
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr