Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a function cannot have _ as name #5351

Closed
vicuna opened this issue Aug 28, 2011 · 4 comments
Closed

a function cannot have _ as name #5351

vicuna opened this issue Aug 28, 2011 · 4 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented Aug 28, 2011

Original bug ID: 5351
Reporter: gerd
Assigned to: @lefessan
Status: closed (set by @xavierleroy on 2013-08-31T10:44:24Z)
Resolution: suspended
Priority: normal
Severity: minor
Version: 3.12.1
Category: ~DO NOT USE (was: OCaml general)
Monitored by: abdallah @protz @lefessan @ygrek @hcarty @Chris00

Bug 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.

@vicuna
Copy link
Author

vicuna commented Aug 29, 2011

Comment author: @Chris00

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 _ () =”.

@vicuna
Copy link
Author

vicuna commented Sep 3, 2011

Comment author: @Chris00

Also, “let _ () = ...” is accepted if one uses camlp4 — probably because it is transformed into ”let _ = fun () -> ...”.

@vicuna
Copy link
Author

vicuna commented Sep 6, 2011

Comment author: @xavierleroy

"_" 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)

@vicuna
Copy link
Author

vicuna commented Jan 17, 2012

Comment author: @lefessan

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants