Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004073OCamlOCaml generalpublic2006-07-28 10:062006-09-21 16:34
Reporterprevosto 
Assigned Tomaranget 
PrioritynormalSeveritytweakReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version3.09.2 
Target VersionFixed in Version 
Summary0004073: Spurious 'E' warning (fragile pattern-matching)
DescriptionIn certain cases, ocaml warns that a matching is fragile while it isn't:
is002447:~ $ ocaml -w E
        Objective Caml version 3.09.2
# type foo = A | B;;
type foo = A | B
# let f = function A,_ | _, A -> A | B,B -> B;;
val f : foo * foo -> foo = <fun>
# let f = function A,_ -> A | _,A -> A | B,B -> B;;
Characters 28-29:
Warning E: this pattern is fragile. It would hide
the addition of new constructors to the data types it matches.
  let f = function A,_ -> A | _,A -> A | B,B -> B;;
                              ^
val f : foo * foo -> foo = <fun>

The two definitions of f are equivalent. Moreover, if we indeed add a constructor, the matching becomes incomplete (but it is flagged as fragile, which is a bit contradictory):
# type bar = A | B | C;;
type bar = A | B | C
# let f = function A,_ -> A | _,A -> A | B,B -> B;;
Characters 10-49:
Warning P: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
(C, (C|B))
Characters 30-31:
Warning E: this pattern is fragile. It would hide
the addition of new constructors to the data types it matches.
    let f = function A,_ -> A | _,A -> A | B,B -> B;;
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    let f = function A,_ -> A | _,A -> A | B,B -> B;;
                                ^
val f : bar * bar -> bar = <fun>
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0003794)
maranget (manager)
2006-09-21 16:34

I think I have closed the issue.

Fragile matchings are no implemented by following definition.

A matching is said to be fragile when the addition of a constructor
to one of the types it matches does not result in a 'non-exhaustive' warning.

'One of the types it matches' means that there is a constructor that
belongs to the said type in the matching.

Before, there was a vague notion of 'fragile pattern' with no clear
meaning.


--Luc

- Issue History
Date Modified Username Field Change
2006-07-28 10:06 prevosto New Issue
2006-08-29 16:54 doligez Status new => acknowledged
2006-09-20 19:12 maranget Status acknowledged => assigned
2006-09-20 19:12 maranget Assigned To => maranget
2006-09-21 16:34 maranget Note Added: 0003794
2006-09-21 16:34 maranget Status assigned => closed
2006-09-21 16:34 maranget Resolution open => fixed


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker