Closed ilya-klyuchnikov closed 4 years ago
Thanks for the issue report! Type synonyms were added recently and there is indeed a missing cycles check. Synonyms are expanded lazily by the type checker and the occurs check won't see the recursion. Since we don't support recursive types elsewhere, I think the best fix is an upfront check for cycles in the type synonym definitions. I will add this check soon.
Thanks for the quick reply and for the great project!
I guess it would be worth to mention more explicitly in the beginning of the README that Expresso doesn't support recursive structural data types.
(There is a note that "Note that records cannot refer to themselves, as Expresso does not support type-level recursion." though - but it is more like a side note).
The thing is that for example Ocaml does support recursive polymorphic variants and the following code is valid for Ocaml compiler:
let un_box box default = match box with
| `Box content -> content
| `NoBox -> default
let un_box1 box1 = match box1 with
| `Box1 content -> content
let un_box2 x = un_box (un_box1 x) x
The types are:
val un_box : [< `Box of 'a | `NoBox ] -> 'a -> 'a = <fun>
val un_box1 : [< `Box1 of 'a ] -> 'a = <fun>
val un_box2 : ([< `Box1 of [< `Box of 'a | `NoBox ] ] as 'a) -> 'a = <fun>
I have added a check to prohibit recursive synonym definitions and updated the README. I'm not sure that recursive records is something I would be keen to try and support, especially given the configuration language use-case that I am exploring. I would rather explore an impredicative type system, which would get us nicer first-class modules and better type singatures for records-as-modules.
An example:
This is not accepted:
However, just replacing
un_box
withun_box_spec
in the definition ofun_box_record
is accepted. Note thatun_box_spec
is the sameun_box
but with a more special type.Basically, what I have done manually is just type instantiation.
I understand that this example is a tricky one with "recursive records" and it can be ok to explicitly forbid their usages. But to me it seems that either both variants of this program should be accepted or rejected.