| Anonymous | Login | Signup for a new account | 2013-05-18 18:28 CEST | ![]() |
| Main | My View | View Issues | Change Log | Roadmap |
| View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | |||||||||||
| ID | Project | Category | View Status | Date Submitted | Last Update | |||||||
| 0005351 | OCaml | OCaml general | public | 2011-08-28 22:02 | 2012-01-17 23:25 | |||||||
| Reporter | gerd | |||||||||||
| Assigned To | lefessan | |||||||||||
| Priority | normal | Severity | minor | Reproducibility | always | |||||||
| Status | resolved | Resolution | suspended | |||||||||
| Platform | OS | OS Version | ||||||||||
| Product Version | 3.12.1 | |||||||||||
| Target Version | Fixed in Version | |||||||||||
| Summary | 0005351: a function cannot have _ as name | |||||||||||
| Description | I 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 Information | Ideally, a function with name _ would not generate code at all. Btw, let _ = fun x -> x is accepted. | |||||||||||
| Tags | No tags attached. | |||||||||||
| Attached Files | ||||||||||||
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 |
| Copyright © 2000 - 2011 MantisBT Group |