Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006056OCamlOCaml typingpublic2013-06-27 20:282013-06-28 12:50
Assigned Togarrigue 
PlatformOSOS Version
Product Version4.00.1 
Target VersionFixed in Version4.01.0+dev 
Summary0006056: [non-expansivity issue] Using 'match' prevents generalization [of values], even though using 'if' allows it
DescriptionIn the following two examples, using an 'if' statement allows the function to be generalized, but using 'match' prevents it.

let using_if b =
  let f =
    if b
    then fun x -> x
    else fun x -> x
  f 0,f
(* val using_if : bool -> int * ('a -> 'a) = <fun> *)

let using_match b =
  let f =
    match b with
    | true -> fun x -> x
    | false -> fun x -> x
  f 0,f
(* val using_match : bool -> int * (int -> int) = <fun> *)
Additional InformationA colleague of mine suggests that this is due to the fact that 'match' statements are never considered to be nonexpansive.
TagsNo tags attached.
Attached Files

- Relationships
related to 0006057resolvedgarrigue « match e with p -> » does not generalize « e » 

-  Notes
garrigue (manager)
2013-06-28 12:08

Actually, this is wrong: in "match e with p -> ...", e is generalized.
What is not generalized is the result of the match expression.
As you write, match expressions are never generalized,
whereas let expressions are generalized if subexpressions are non expansive.
So this should probably be done the same way.
Note that lazy patterns may cause side-effects, but this is already handled
by the typing of lazy values (i.e. a lazy value is not generalizable if forcing it
would cause side-effects)
garrigue (manager)
2013-06-28 12:15

My bad. I thought this was done, but it is not.
Both 6056 and 6057 should be done soon.
Actually 6057 is the harder one (but not by a big difference).
garrigue (manager)
2013-06-28 12:50

Fixed in trunk and 4.01 (before release).
Revisions 13845 and 13847.

This had to be fixed because let's that contain GADTs are automatically converted to match, so the difference in behavior could be observable.

- Issue History
Date Modified Username Field Change
2013-06-27 20:28 elnatan New Issue
2013-06-28 09:47 protz Status new => acknowledged
2013-06-28 09:47 protz Summary Using 'match' prevents generalization, even though using 'if' allows it => [non-expansivity issue] Using 'match' prevents generalization [of values], even though using 'if' allows it
2013-06-28 09:54 protz Relationship added related to 0006057
2013-06-28 12:08 garrigue Note Added: 0009629
2013-06-28 12:15 garrigue Note Added: 0009630
2013-06-28 12:50 garrigue Note Added: 0009632
2013-06-28 12:50 garrigue Status acknowledged => resolved
2013-06-28 12:50 garrigue Fixed in Version => 4.01.0+dev
2013-06-28 12:50 garrigue Resolution open => fixed
2013-06-28 12:50 garrigue Assigned To => garrigue

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker