I noticed while writing Elpi code that it is possible to write code like this
kind foo type.
type X int -> foo.
type Y Z -> foo.
without Elpi Typecheck.
giving any errors. Is there a reason for this, or is it a bug? If there is a use case I would be very interested to see how it would work, as I can't find any that do anything.
Or is it simply a capital letter name that you then can't use anywhere anymore?
Hello. IIUC the value Z
here is an Elpi variable in the type. You are in fact creating a polymorphic constructor Y
for foo
that takes any value and returns a foo
.
kind list type -> type.
type nil A -> list A.
type cons A -> list A -> list A.
Does that help?
When I try to use either X
or Y
in a later piece of code it doesn't work as they are interpreted as unification variables, not constructors of foo. It happens because they are capital letters I think. That was what my question was mostly about, sorry for formulating it badly. But I do see now how the Z would work.
Also the vscode syntax highlighting doesn't work anymore at that point, so it feels like a weird edge case.
@Enzo Crance I'm surprised, I'd also expect a unification variable rather than polymorphism — can you build a list int and a list string with those constructors?
@Luko van der Maas yeah everything uppercase is a unification variable, I'm surprised that's accepted for the "thing to type"... Maybe it could force the variable and its solutions to have that type?
It is a bug
The type checker is a really simple piece of code, and here the parser is too permissive
Last updated: Oct 13 2024 at 01:02 UTC