Skip to content

Surprising interaction between parenthesizing applications and default arguments #7832

@vicuna

Description

@vicuna

Original bug ID: 7832
Reporter: @jberdine
Assigned to: @garrigue
Status: resolved (set by @garrigue on 2018-07-25T00:43:05Z)
Resolution: not a bug
Priority: low
Severity: minor
Version: 4.07.0
Category: typing
Monitored by: @jberdine

Bug description

A bug in ocamlformat found by hhugo uncovered some, to me, surprising sensitivity of the type checker to the presence of parentheses around applications. See the following toplevel interaction for example:

# let id x = x;; val id : 'a -> 'a = # let plus a ?(b=0) c = a + b + c;; val plus : int -> ?b:int -> int -> int = # id (plus 1);; - : ?b:int -> int -> int = # id (plus 1) 1;; - : int = 2 # (id (plus 1)) ~b:1;; - : int -> int = # id (plus 1) ~b:1;; Error: This expression has type ?b:int -> int -> int but an expression was expected of type b:'a -> 'b

Note the last two expressions are the same except for two nested 1-argument applications versus a single 2-argument application, but the first types and the second doesn't. Is this difference expected? Is there a description of when such distinctions are important? (Ideally ocamlformat would emit the parens where needed but not have to for all nested applications, so I'm looking for some syntactic criterion to use to distinguish which Parsetrees need the parens and which don't.)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions