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

camlp4r (?) does not respect the constructor's arity #5267

Closed
vicuna opened this issue May 17, 2011 · 3 comments
Closed

camlp4r (?) does not respect the constructor's arity #5267

vicuna opened this issue May 17, 2011 · 3 comments

Comments

@vicuna
Copy link

vicuna commented May 17, 2011

Original bug ID: 5267
Reporter: Dmitry Grebeniuk
Status: closed (set by @diml on 2016-12-07T17:27:37Z)
Resolution: open
Priority: normal
Severity: minor
Version: 3.13.0+dev
Target version: later
Category: -for Camlp4 use https://github.com/ocaml/camlp4/issues

Bug description

type t1 = [ A of int ];

type t1 = [ A of int ]

fun [ A "a" True -> () ];

Characters 6-16:
fun [ A "a" True -> () ];
^^^^^^^^^^
Error: This pattern matches values of type (string * bool)
but a pattern was expected which matches values of type int

The error here should be more like to "Error: The constructor A expects 1 argument(s), but is applied here to 2 argument(s)"

Maybe this is a minor issue itself, but it leads to very hard to find errors when the wrong type infers from pattern matching and spreads all over the code:

type t 'a = [ T of 'a ];

type t 'a = [ T of 'a ]

value f x = match x with [ T a b -> a ];

value f : t ('a * 'b) -> 'a =

@vicuna
Copy link
Author

vicuna commented Jul 10, 2012

Comment author: @damiendoligez

This is not really a camlp4 problem, because the compiler does automatic tuplification of constructor arguments when you pass several arguments to a unary constructor:

$ ocaml
Objective Caml version 3.12.1

type t1 = A of int;;

type t1 = A of int

function A ("a", true) -> ();;

Error: This pattern matches values of type string * bool
but a pattern was expected which matches values of type int

@vicuna
Copy link
Author

vicuna commented Sep 20, 2012

Comment author: @damiendoligez

Definitely not a camlp4 problem. We could have a better error message for the first example, but there's nothing we can do to prevent propagation in the second example.

@vicuna
Copy link
Author

vicuna commented Dec 7, 2016

Comment author: @diml

Camlp4 is now a separate project. Please re-open a ticket on github [1] if you are still interested in seeing the original issue fixed.

[1] https://github.com/ocaml/camlp4/issues

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

1 participant