Version française
Home     About     Download     Resources     Contact us    
Browse thread
RE: [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: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] Pattern matcher no more supposed to warn on non exhaustive patterns ?
> The issue with threads is a bit more troublesome.  Consider:
> 
>   let x : (int->int) option ref = ref (Some (fun x -> x));;
> 
>   let foo z =
>       match z with
>         {contents=None} -> 0
>       | {contents=Some(f)} -> f(0);
>
> The question is, does Caml core dump because the pattern matcher
> assumes that the contents *has* to be a Some(-) in the second
> case?  Or does it do the derefence and check atomically?  Or
> does it add a default case that raises a Match exception?  

It reads the "contents" field once, let-binds its value, and use it in
the remainder of the "match":

       (function z/52
         (let (match/54 (field 0 z/52))
           (if match/54 (apply (field 0 match/54) 0) 0))))

Since reading a record field is atomic, no crash can occur: foo either
matches on the "old" or the "new" contents of the reference.

- Xavier Leroy
-------------------
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