hkust-taco / mlscript

The MLscript programming language. Functional and object-oriented; structurally typed and sound; with powerful type inference. Soon to have full interop with TypeScript!
https://hkust-taco.github.io/mlscript
MIT License
174 stars 27 forks source link

Fix `let` annotation handling #226

Closed NeilKleistGao closed 1 month ago

NeilKleistGao commented 1 month ago

The annotation for let-binding was not handled correctly:

// the annotation `forall 'a : 'a -> 'a` is ignored
fun foo(f) =
  let g: forall 'a : 'a -> 'a = x => f(x) in g(123)
//│ fun foo: forall 'a. (123 -> 'a) -> 'a

fun foo(f) =
  let g = (x => f(x)): forall 'a : 'a -> 'a in g(123)
//│ fun foo: (??a -> ??a0) -> 123

This simple PR fixed this problem so that two given functions above have the same type:

fun foo(f) =
  let g = (x => f(x)): forall 'a : 'a -> 'a in g(123)
//│ fun foo: (??a -> ??a0) -> 123

fun foo(f) =
  let g: forall 'a : 'a -> 'a = x => f(x) in g(123)
//│ fun foo: (??a -> ??a0) -> 123