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

In type definitions, type constructors are silently mistaken as data constructors #30

Open
ulidtko opened this issue Oct 2, 2015 · 0 comments

Comments

@ulidtko
Copy link

ulidtko commented Oct 2, 2015

It's easy to make an error like this:

:- import_module list, int.

:- type myintlist ---> list(int).
:- func MyMerge(myintlist, myintlist) = myintlist.
MyMerge(A, B) = A ++ B.

The compiler says:

hello.m:013: In clause for function `'/3:
hello.m:013:   in function result term of clause head:
hello.m:013:   type error in unification of variable `HeadVar__4'
hello.m:013:   and functor `++/2'.
hello.m:013:   variable `HeadVar__4' has type `hello.myintlist',
hello.m:013:   functor `++/2' has type
hello.m:013:   `(list.list(T) ++ list.list(T)): list.list(T)'.

which is horrific! (and even worse for set). It gives no insight whatsoever.

Corrected code is:

:- type myintlist ---> mycon(list(int)).
:- func MyMerge(myintlist, myintlist) = myintlist.
MyMerge(mycon(A), mycon(B)) = mycon(A ++ B).

and, perhaps, experienced Mercury coder won't do this mistake — but newbies likely will.

My point is that it'd be easy to check if a user-defined data constructor name clashes with a type/type constructor name in scope, and issue a warning or suggestion for such a type definition. It'd help avoid the error.

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

No branches or pull requests

1 participant