Change tuple typing syntax #600
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "github/fork/radrow/tuple-type"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Created by: radrow
Motivation
Previously the syntax for tuple types was identical to tuple values:
Problem with this notation is that it is shared with multi argument function domain which causes
to mean both a function that takes two ints as an argument and a function that takes a single pair of ints. Our parser forbids ambiguous parsing results and takes strategy to parse domain as a tuple and turn it into an argument list which makes having a tuple or unit as the only argument impossible. Tricks like
((int, int)) => int
do not work, because((int, int))
is parsed literally as(int, int)
which is treated at first as a tuple and then...as a list of args.
Disability to express some types beside just being not nice can lead to further problems, for instance in #108 where the compiler expects programmer to explicitly specify the desired type.
Syntax changes
This PR solves this problem by introducing new syntax for typing tuples:
Now,
('a * 'b) => 'a
is clearly different from('a, 'b) => 'c
, same forunit => 'a
and() => 'a
.The
x * y
syntax has priority between lambda and type application / bytes notation, so'a * 'b => 'c
means('a * 'b) => 'c
.This notation is mainly inspired by SML language which uses same syntax for
unit
and non-zero tuples. Sophia is said to belong to ML-family, so this update makes some sense in this context. Also, Cartesian product is commonly encoded this way, so the change shouldn't bring a lot of confusion.Created by: radrow
cc @hanssv @UlfNorell
Created by: UlfNorell
Double parens? Should probably be
Created by: radrow
I was not aware about this dollar notation. Sure
Created by: UlfNorell
Review: Approved
Created by: hanssv
Review: Approved
👍
Merged by: UlfNorell at 2019-08-05 07:13:31 UTC