kfl / mosml

Moscow ML is a light-weight implementation of Standard ML (SML), a strict functional language widely used in teaching and research.
http://mosml.org
341 stars 42 forks source link

Elaboration of non-linear patterns #55

Open PH111P opened 5 years ago

PH111P commented 5 years ago

MosML elaborates the following code:

fun f x x = x;

as

> val ('a, 'b) f = fn : 'a -> 'b -> 'b

which does not conform to the Definition of SML'97. In particular, the code should simplify to

val rec f = fn vid1 => fn vid2 => case (vid1, vid2) of (x, x) => x;

which is in turn rejected by MosML with the following error message:

! Toplevel input:
! val rec f = fn vid1 => fn vid2 => case (vid1, vid2) of (x, x) => x;
!                                                        ^
! Illegal rebinding of x: the same value identifier is bound twice in a pattern

(Tested with version 2.10 on Arch Linux)

kfl commented 5 years ago

Nice catch.

Thanks for the report.