* [Caml-list] exhaustiveness checking within a submatch @ 2013-10-10 8:00 Martin DeMello 2013-10-10 8:07 ` David Allsopp 0 siblings, 1 reply; 4+ messages in thread From: Martin DeMello @ 2013-10-10 8:00 UTC (permalink / raw) To: OCaml List Just curious as to why the compiler can't handle this, since in theory everything is statically deducible: # type test = A | B | C | D;; type test = A | B | C | D # let f = A;; val f : test = A # match f with A -> 1 | B -> 2 | C | D -> ( match f with C -> 3 | D -> 4);; Characters 40-71: Warning 8: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: (A|B) Characters 40-71: Warning 8: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: (A|B) - : int = 1 martin ^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [Caml-list] exhaustiveness checking within a submatch 2013-10-10 8:00 [Caml-list] exhaustiveness checking within a submatch Martin DeMello @ 2013-10-10 8:07 ` David Allsopp 2013-10-10 8:09 ` David House 0 siblings, 1 reply; 4+ messages in thread From: David Allsopp @ 2013-10-10 8:07 UTC (permalink / raw) To: OCaml List Martin DeMello wrote: > Just curious as to why the compiler can't handle this, since in theory > everything is statically deducible: > > # type test = A | B | C | D;; > type test = A | B | C | D > > # let f = A;; > val f : test = A > > # match f with A -> 1 | B -> 2 | C | D -> ( match f with C -> 3 | D -> > 4);; > Characters 40-71: > Warning > 8: this pattern-matching is not exhaustive. > Here is an > example of a value that is not matched: > (A|B) > Characters 40-71: > Warning 8: this pattern-matching is not exhaustive. > Here is an example of a value that is not matched: > (A|B) > - : int = 1 http://caml.inria.fr/pub/ml-archives/caml-list/2007/02/d35648b13d76f1717edbf41101dc913f.en.html David ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] exhaustiveness checking within a submatch 2013-10-10 8:07 ` David Allsopp @ 2013-10-10 8:09 ` David House 2013-10-10 17:32 ` Martin DeMello 0 siblings, 1 reply; 4+ messages in thread From: David House @ 2013-10-10 8:09 UTC (permalink / raw) To: David Allsopp; +Cc: OCaml List This does actually work with polymorphic variants, as long as you rename the thing in the submatch: match f with `A -> 1 | `B -> 2 | (`C | `D as foo) -> match foo with `C -> 3 | `D -> 4 On 10 October 2013 09:07, David Allsopp <dra-news@metastack.com> wrote: > Martin DeMello wrote: >> Just curious as to why the compiler can't handle this, since in theory >> everything is statically deducible: >> >> # type test = A | B | C | D;; >> type test = A | B | C | D >> >> # let f = A;; >> val f : test = A >> >> # match f with A -> 1 | B -> 2 | C | D -> ( match f with C -> 3 | D -> >> 4);; >> Characters 40-71: >> Warning >> 8: this pattern-matching is not exhaustive. >> Here is an >> example of a value that is not matched: >> (A|B) >> Characters 40-71: >> Warning 8: this pattern-matching is not exhaustive. >> Here is an example of a value that is not matched: >> (A|B) >> - : int = 1 > > http://caml.inria.fr/pub/ml-archives/caml-list/2007/02/d35648b13d76f1717edbf41101dc913f.en.html > > > David > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] exhaustiveness checking within a submatch 2013-10-10 8:09 ` David House @ 2013-10-10 17:32 ` Martin DeMello 0 siblings, 0 replies; 4+ messages in thread From: Martin DeMello @ 2013-10-10 17:32 UTC (permalink / raw) To: David House; +Cc: David Allsopp, OCaml List Thanks. So I guess the answer boils down to "possible but not worth it", which makes sense. martin On Thu, Oct 10, 2013 at 1:09 AM, David House <dhouse@janestreet.com> wrote: > This does actually work with polymorphic variants, as long as you > rename the thing in the submatch: > > match f with `A -> 1 | `B -> 2 | (`C | `D as foo) -> match foo with `C > -> 3 | `D -> 4 > > On 10 October 2013 09:07, David Allsopp <dra-news@metastack.com> wrote: >> Martin DeMello wrote: >>> Just curious as to why the compiler can't handle this, since in theory >>> everything is statically deducible: >>> >>> # type test = A | B | C | D;; >>> type test = A | B | C | D >>> >>> # let f = A;; >>> val f : test = A >>> >>> # match f with A -> 1 | B -> 2 | C | D -> ( match f with C -> 3 | D -> >>> 4);; >>> Characters 40-71: >>> Warning >>> 8: this pattern-matching is not exhaustive. >>> Here is an >>> example of a value that is not matched: >>> (A|B) >>> Characters 40-71: >>> Warning 8: this pattern-matching is not exhaustive. >>> Here is an example of a value that is not matched: >>> (A|B) >>> - : int = 1 >> >> http://caml.inria.fr/pub/ml-archives/caml-list/2007/02/d35648b13d76f1717edbf41101dc913f.en.html >> >> >> David >> >> -- >> Caml-list mailing list. Subscription management and archives: >> https://sympa.inria.fr/sympa/arc/caml-list >> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >> Bug reports: http://caml.inria.fr/bin/caml-bugs > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-10-10 17:32 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2013-10-10 8:00 [Caml-list] exhaustiveness checking within a submatch Martin DeMello 2013-10-10 8:07 ` David Allsopp 2013-10-10 8:09 ` David House 2013-10-10 17:32 ` Martin DeMello
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox