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

"let _ : t = v;;" is not accepted without camlp4o #5362

Closed
vicuna opened this issue Sep 27, 2011 · 4 comments
Closed

"let _ : t = v;;" is not accepted without camlp4o #5362

vicuna opened this issue Sep 27, 2011 · 4 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented Sep 27, 2011

Original bug ID: 5362
Reporter: Dmitry Grebeniuk
Assigned to: @mshinwell
Status: resolved (set by @mshinwell on 2016-12-12T16:01:44Z)
Resolution: fixed
Priority: normal
Severity: feature
Version: 3.12.1
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @ygrek "Julien Signoles"

Bug description

"let _ : t = v" should be accepted just like "let x : t = v" even without camlp4o:

$ ocaml
Objective Caml version 3.12.1+rc1

let x : int = 1;;

val x : int = 1

let _ : int = 1;;

Error: Syntax error

#use "topfind";;

  • : unit = ()
    Findlib has been successfully loaded. Additional directives:
    #require "package";; to load a package
    #list;; to list the available packages
    #camlp4o;; to load camlp4 (standard syntax)
    #camlp4r;; to load camlp4 (revised syntax)
    #predicates "p,q,...";; to set these predicates
    Topfind.reset();; to force that packages will be reloaded
    #thread;; to enable threads

  • : unit = ()

#camlp4o;;

/home/gds/dev/ovm/ocaml/lib/dynlink.cma: loaded
/home/gds/dev/ovm/ocaml/lib/camlp4: added to search path
/home/gds/dev/ovm/ocaml/lib/camlp4/camlp4o.cma: loaded
Camlp4 Parsing version 3.12.1+rc1

let x : int = 1;;

val x : int = 1

let _ : int = 1;;

  • : int = 1

Also it's strange that toplevel output ("- : int = 1") differs from revised syntax:

$ ocaml
Objective Caml version 3.12.1+rc1

#use "topfind";;;

  • : unit = ()
    Findlib has been successfully loaded. Additional directives:
    #require "package";; to load a package
    #list;; to list the available packages
    #camlp4o;; to load camlp4 (standard syntax)
    #camlp4r;; to load camlp4 (revised syntax)
    #predicates "p,q,...";; to set these predicates
    Topfind.reset();; to force that packages will be reloaded
    #thread;; to enable threads

  • : unit = ()

#camlp4r;;

/home/gds/dev/ovm/ocaml/lib/dynlink.cma: loaded
/home/gds/dev/ovm/ocaml/lib/camlp4: added to search path
/home/gds/dev/ovm/ocaml/lib/camlp4/camlp4r.cma: loaded
Camlp4 Parsing version 3.12.1+rc1

value _ : int = 1;

(there is no output at all)

@vicuna
Copy link
Author

vicuna commented Sep 27, 2011

Comment author: @garrigue

We have here a subtle point.
In the OCaml grammar, a let definition is either

let =

or

let <args ...> [: ] =

In patterns, a type annotation requires parentheses, so

let (_ : ) =

is of course ok, but

let _ : =

doesn't fit either.
The specification of the manual fits this description.

@vicuna
Copy link
Author

vicuna commented Sep 27, 2011

Comment author: Dmitry Grebeniuk

Yes, you are right.
So, please treat this issue not as "bug report", but as a "feature wish".
It's very convenient to think about "_" pattern as "/dev/null variable", "sink variable", "value that is will be bound to anything you'll bind it to". So, I personally like the #camlp4o and #camlp4r behaviour. However, I'm using revised syntax almost always, so this issue will cause inconvenience/misunderstanding only for "plain toplevel users".

@vicuna
Copy link
Author

vicuna commented Oct 4, 2011

Comment author: Julien Signoles

Usually I use "let __ : type = expr" (double underscore) when I want to use such a pattern.

@vicuna
Copy link
Author

vicuna commented Dec 12, 2016

Comment author: @mshinwell

This issue appears to have been fixed.

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