Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005351OCamlOCaml generalpublic2011-08-28 22:022013-08-31 12:44
Reportergerd 
Assigned Tolefessan 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionsuspended 
PlatformOSOS Version
Product Version3.12.1 
Target VersionFixed in Version 
Summary0005351: a function cannot have _ as name
DescriptionI think this function definition is reasonable, but the compiler rejects it with syntax error:

let _ (x : some_object_type) =
  (x :> some_super_object_type)

This is useful as a compile-time assertion that some_object_type is a subtype of some_super_object_type. The compiler accepts this if I change the function name to _f. However, I'm not interested in this function as such, but only in the effect of the definition on type checking.
Additional InformationIdeally, a function with name _ would not generate code at all.

Btw, let _ = fun x -> x is accepted.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0006107)
Christophe Troestler (reporter)
2011-08-29 17:28

I personally would use it to disable some part of the code — say some tests during development that I would like to keep for reference (this is in research code, not production one). It is easy to switch from “let () =” to “let _ () =”.
(0006111)
Christophe Troestler (reporter)
2011-09-03 20:22

Also, “let _ () = ...” is accepted if one uses camlp4 — probably because it is transformed into ”let _ = fun () -> ...”.
(0006116)
xleroy (administrator)
2011-09-06 16:29

"_" is a pattern, not an identifier, so
     let _ = ...
is accepted just like
     let (x,y,z) = ...
is accepted. However, it wouldn't make sense to accept
     let (x,y,z) arg = ...
as some kind of function definition... So, for this reason, I'm uncomfortable with
     let _ arg = ...

In your particular example, what about writing the below?

let _ = fun (x : some_object_type) -> (x :> some_super_object_type)

(0006711)
lefessan (developer)
2012-01-17 23:25

This feature is "suspended" until new uses of anonymous functions appear. In the meantime, you can use Xavier's workaround:

let _ = fun (x : some_object_type) -> (x :> some_super_object_type)

- Issue History
Date Modified Username Field Change
2011-08-28 22:02 gerd New Issue
2011-08-29 17:28 Christophe Troestler Note Added: 0006107
2011-09-03 20:22 Christophe Troestler Note Added: 0006111
2011-09-06 16:29 xleroy Note Added: 0006116
2011-09-06 16:29 xleroy Status new => feedback
2012-01-17 23:25 lefessan Note Added: 0006711
2012-01-17 23:25 lefessan Status feedback => resolved
2012-01-17 23:25 lefessan Resolution open => suspended
2012-01-17 23:25 lefessan Assigned To => lefessan
2013-08-31 12:44 xleroy Status resolved => closed


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker