Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007386OCamltypingpublic2016-10-14 22:132017-02-23 17:06
Reportergasche 
Assigned To 
PrioritynormalSeverityfeatureReproducibilityhave not tried
StatusacknowledgedResolutionopen 
PlatformOSOS Version
Product Version4.03.0 
Target VersionFixed in Version 
Summary0007386: In or-patterns, propagate path disambiguation from one prefixed constructor to other constructors
DescriptionIf we write a record pattern or expression with fields { a; M.b; c }, it is understood as equivalent to { M.a; M.b; M.c }. I would like this property to also hold of variant constructors appear in an or-pattern (or at the head of a list of clauses): (A | M.B | C) should be equivalent to (M.A | M.B | M.C), and

  | A -> ...
  | M.B -> ...
  | C -> ...

equivalent to

  | M.A -> ...
  | M.B -> ...
  | M.C -> ...
Additional InformationHere is a concrete example I just had of a situation where this feature would be useful to me:

  let fill_cache article_map =
    let open Canopy_content in
    let fold_fn key value acc =
      value () >>= fun content ->
      date_updated_created key >>= fun (updated, created) ->
      let uri = String.concat "/" key in
      match of_string ~uri ~content ~created ~updated with
      | Ok article ->
        article_map := KeyMap.add key article !article_map;
        Lwt.return acc
      | Error error ->
        let error_msg = Printf.sprintf "Error while parsing %s: %s" uri error in
        Lwt.return (error_msg::acc)
      | Unknown ->
        let error_msg = Printf.sprintf "%s : Unknown content type" uri in
        Lwt.return (error_msg::acc)
    in
    new_task () >>= fun t ->
    fold (t "Folding through values") fold_fn []

This is code is from <https://github.com/Engil/Canopy> [^] . When compiled from 4.03, it raises the following warnings:

  File "canopy_store.ml", line 78, characters 4-716:
  Warning 45: this open statement shadows the constructor Ok (which is later used)
  File "canopy_store.ml", line 78, characters 4-716:
  Warning 45: this open statement shadows the constructor Error (which is later used)

The best way I see to silence the warning is to write

      match of_string ~uri ~content ~created ~updated with
      | Canopy_content.Ok article ->
        article_map := KeyMap.add key article !article_map;
        Lwt.return acc
      | Canopy_content.Error error ->
        let error_msg = Printf.sprintf "Error while parsing %s: %s" uri error in
        Lwt.return (error_msg::acc)
      | Unknown ->
        let error_msg = Printf.sprintf "%s : Unknown content type" uri in
        Lwt.return (error_msg::acc)

but I would find it natural if it was possible to prefix only the first constructor.

We previously discussed this feature during the type-based-constructor/field-disambiguation debate, but the applicability scope I had in mind was too broad and with an unclear specification. I believe that "are in a single or-pattern" (or, as a generalization, at the head of the clauses of a matching) is a clear, simple and useful specification.
TagsNo tags attached.
Attached Files

- Relationships
related to 0005759resolvedgarrigue Using well-disciplined type-propagation to disambiguate label and constructor names 
related to 0005980acknowledgedfrisch warning on use of an identifier shadowed by module open -- feature implemented, but refinements still possible 
related to 0007443resolvedoctachron Doubtful "unused open" warning on module used for record field disambiguation 
child of 0006951acknowledged Meta-issue on ambiguity warnings 
child of 0007409confirmed meta-issue on type and path propagation 

-  Notes
(0016404)
gasche (developer)
2016-10-14 22:15

I realize now that another way to avoid this warning would be to not warn when type-directed disambiguation in fact selects a non-ambiguous candidate: this means that the syntactic ambiguity is in fact benign, as the types determine the only possible choice. That's a feature request for the ambiguity warning.
(0016406)
frisch (developer)
2016-10-17 09:39

1) Another direction which would address this specific case is to disambiguate using all constructors "at the same position" (in your example, lookup a type containing the three constructors Ok/Error/Unknown), as we do for records. The definition of "at the same position" could be the same as the one used to propagate paths.

2) Do you think that extending the notion of "at the same position" to traverse tuples would add too much complexity to this proposal? (i.e. support function (M.A, _) -> ... | (B, _) -> ...).

- Issue History
Date Modified Username Field Change
2016-10-14 22:13 gasche New Issue
2016-10-14 22:15 gasche Note Added: 0016404
2016-10-14 22:16 gasche Relationship added related to 0005759
2016-10-14 22:16 gasche Relationship added child of 0006951
2016-10-14 22:17 gasche Relationship added related to 0005980
2016-10-17 09:39 frisch Note Added: 0016406
2016-11-12 16:20 gasche Relationship added child of 0007409
2016-12-28 02:48 gasche Relationship added related to 0007443
2017-02-23 16:45 doligez Category OCaml typing => typing
2017-02-23 17:06 xleroy Status new => acknowledged
2017-02-23 17:06 xleroy Target Version 4.05.0+dev =>


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker