Skip to content

Commit

Permalink
Specially type lists for better error messages
Browse files Browse the repository at this point in the history
twitu committed Sep 11, 2023
1 parent 92b2566 commit 25d752d
Showing 13 changed files with 6,974 additions and 3,874 deletions.
19 changes: 19 additions & 0 deletions shared/src/main/scala/hmloc/Typer.scala
Original file line number Diff line number Diff line change
@@ -372,6 +372,25 @@ class Typer(var dbg: Boolean, var verbose: Bool, var explainErrors: Bool)
val param_ty = typePattern(pat)(newCtx, raise, vars)
val body_ty = typeTerm(body)(newCtx, raise, vars)
FunctionType(param_ty, body_ty)(tp(term.toLoc, "function"))
// specialize Cons Nil application for better error messages
case cons@App(Var("Cons"), Tup(v :: Var("Nil") :: Nil)) =>
// version 2 inline Nil
// val arg_var = freshVar(tp(v.toCoveringLoc, "cons arg"))
// val v_ty = typeTerm(v)
// con(v_ty, arg_var, arg_var)
// TypeRef(TypeName("list"), arg_var :: Nil)(tp(cons.toLoc, "cons"))
// version 2 remove Nil completely
val v_ty = typeTerm(v)
TypeRef(TypeName("list"), v_ty :: Nil)(tp(cons.toLoc, "cons"))
// specialize Cons application for better error messages
case cons@App(Var("Cons"), Tup(v :: vs :: Nil)) =>
// version 2 simplified style
val arg_var = freshVar(tp(v.toCoveringLoc, "cons arg"))
val v_ty = typeTerm(v)
con(v_ty, arg_var, arg_var)
val vs_ty = typeTerm(vs)
val res_ty = TypeRef(TypeName("list"), v_ty :: Nil)(tp(cons.toLoc, "cons"))
con(vs_ty, res_ty, res_ty)
case App(f, a) =>
// version 2 simplified style
val fun_ty = typeTerm(f)
105 changes: 13 additions & 92 deletions shared/src/test/diff/ocaml/Jonathan.mls
Original file line number Diff line number Diff line change
@@ -221,9 +221,9 @@ let rec additivePersistence n =
//│ additivePersistence: 'a -> 'b
//│ where
//│ 'b = bool, int
//│ U max: 6, total: 56
//│ U max: 4, total: 50
//│ UERR 1 errors
//│ L: 0 [bool ~ int, bool <: α121', α121' <: α111', α111' :> int]
//│ L: 0 [bool ~ int, bool <: α115', α115' <: α105', α105' :> int]

// The unification chain terminates at a higher level
// because int is a direct parameter of the list
@@ -233,52 +233,7 @@ let y x = [x]
let k a = if a then [2] else y true
//│ [ERROR] Type `bool` does not match `int`
//│
//│ (bool) ---> (?c) ~~~~ (?a0) ~~~~ (?a) ~~~~ (int)
//│
//│ ◉ (bool) comes from
//│ │ - l.2 let k a = if a then [2] else y true
//│ │ ^^^^
//│ ▼
//│ ◉ (?c) is assumed for
//│ - l.1 let y x = [x]
//│ ^
//│ ◉ (?c * _ list) comes from
//│ │ - l.1 let y x = [x]
//│ │ ^
//│ ▼
//│ ◉ (?a0 * ?a0 list) comes from
//│ - l.1 let y x = [x]
//│ ^
//│ ◉ (?a0) is assumed for
//│ ◉ (?a0 list) comes from
//│ │ - l.1 let y x = [x]
//│ │ ^^^
//│ │ - l.2 let k a = if a then [2] else y true
//│ │ ^^^^^^
//│ │ - l.2 let k a = if a then [2] else y true
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^^^
//│ ▼
//│ ◉ (?b) is assumed for
//│ ▲ - l.2 let k a = if a then [2] else y true
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^^^
//│ │
//│ ◉ (?a list) comes from
//│ - l.2 let k a = if a then [2] else y true
//│ ^^^
//│ ◉ (?a) is assumed for
//│ ◉ (?a * ?a list) comes from
//│ ▲ - l.2 let k a = if a then [2] else y true
//│ │ ^
//│ │
//│ ◉ (int * _ list) comes from
//│ - l.2 let k a = if a then [2] else y true
//│ ^
//│ ◉ (int) comes from
//│ - l.2 let k a = if a then [2] else y true
//│ ^
//│ [ERROR] Type `bool` does not match `int`
//│
//│ (bool) ---> (?b) ~~~~ (?a1) ~~~~ (?a) ~~~~ (?a1) ~~~~ (?a0) ~~~~ (int)
//│ (bool) ---> (?b) ~~~~ (int)
//│
//│ ◉ (bool) comes from
//│ │ - l.2 let k a = if a then [2] else y true
@@ -287,63 +242,29 @@ let k a = if a then [2] else y true
//│ ◉ (?b) is assumed for
//│ - l.1 let y x = [x]
//│ ^
//│ ◉ (?b * ?a list) comes from
//│ │ - l.1 let y x = [x]
//│ │ ^
//│ ▼
//│ ◉ (?a1 * ?a1 list) comes from
//│ - l.1 let y x = [x]
//│ ^
//│ ◉ (?a1) is assumed for
//│ ◉ (?a1 list) comes from
//│ ◉ (?a1 * ?a1 list) comes from
//│ ▲ - l.1 let y x = [x]
//│ │ ^
//│ │
//│ ◉ (?b * ?a list) comes from
//│ - l.1 let y x = [x]
//│ ^
//│ ◉ (?a list) comes from
//│ ◉ (?a) is assumed for
//│ ◉ (?a list) comes from
//│ ◉ (?b * ?a list) comes from
//│ │ - l.1 let y x = [x]
//│ │ ^
//│ ▼
//│ ◉ (?a1 * ?a1 list) comes from
//│ - l.1 let y x = [x]
//│ ^
//│ ◉ (?a1 list) comes from
//│ ◉ (?a1) is assumed for
//│ ◉ (?a1 list) comes from
//│ ◉ (?b list) comes from
//│ │ - l.1 let y x = [x]
//│ │ ^^^
//│ │ - l.2 let k a = if a then [2] else y true
//│ │ ^^^^^^
//│ │ - l.2 let k a = if a then [2] else y true
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^^^
//│ ▼
//│ ◉ (?c) is assumed for
//│ ◉ (?a) is assumed for
//│ ▲ - l.2 let k a = if a then [2] else y true
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^^^
//│ │
//│ ◉ (?a0 list) comes from
//│ ◉ (int list) comes from
//│ - l.2 let k a = if a then [2] else y true
//│ ^^^
//│ ◉ (?a0) is assumed for
//│ ◉ (?a0 * ?a0 list) comes from
//│ ▲ - l.2 let k a = if a then [2] else y true
//│ │ ^
//│ │
//│ ◉ (int * _ list) comes from
//│ - l.2 let k a = if a then [2] else y true
//│ ^
//│ ◉ (int) comes from
//│ - l.2 let k a = if a then [2] else y true
//│ ^
//│ y: 'a -> list['a]
//│ k: bool -> list[bool]
//│ U max: 5, total: 31
//│ UERR 2 errors
//│ L: 1 [bool ~ int, bool <: α132', [α132' - ([[α132']], [[list['a134']]],) ~ ('a133', list['a133'],) - 'a133', L: 0 [([[α132']], [[list['a134']]],) ~ ('a133', list['a133'],), ([[α132']], [[list['a134']]],) <: ('a133', list['a133'],)]], ['a133' - list['a133'] ~ list['a130'] - 'a130', L: 0 [list['a133'] ~ list['a130'], list['a133'] <: α129', α129' :> list['a130']]], ['a130' - ('a130', list['a130'],) ~ ([[int]], [[list['a131']]],) - int, L: 0 [('a130', list['a130'],) ~ ([[int]], [[list['a131']]],), ('a130', list['a130'],) :> ([[int]], [[list['a131']]],)]]]
//│ L: 2 [bool ~ int, bool <: α132', [α132' - ([[α132']], [[list['a134']]],) ~ ('a133', list['a133'],) - 'a133', L: 0 [([[α132']], [[list['a134']]],) ~ ('a133', list['a133'],), ([[α132']], [[list['a134']]],) <: ('a133', list['a133'],)]], ['a133' - list['a133'] ~ list['a134'] - 'a134', L: 1 [list['a133'] ~ list['a134'], [list['a133'] - ('a133', list['a133'],) ~ ([[α132']], [[list['a134']]],) - list['a134'], L: 0 [('a133', list['a133'],) ~ ([[α132']], [[list['a134']]],), ('a133', list['a133'],) :> ([[α132']], [[list['a134']]],)]]]], ['a134' - list['a134'] ~ list['a133'] - 'a133', L: 1 [list['a134'] ~ list['a133'], [list['a134'] - ([[α132']], [[list['a134']]],) ~ ('a133', list['a133'],) - list['a133'], L: 0 [([[α132']], [[list['a134']]],) ~ ('a133', list['a133'],), ([[α132']], [[list['a134']]],) <: ('a133', list['a133'],)]]]], ['a133' - list['a133'] ~ list['a130'] - 'a130', L: 0 [list['a133'] ~ list['a130'], list['a133'] <: α129', α129' :> list['a130']]], ['a130' - ('a130', list['a130'],) ~ ([[int]], [[list['a131']]],) - int, L: 0 [('a130', list['a130'],) ~ ([[int]], [[list['a131']]],), ('a130', list['a130'],) :> ([[int]], [[list['a131']]],)]]]
//│ k: bool -> 'a
//│ where
//│ 'a = list['b], list[int]
//│ 'b = int, bool
//│ U max: 1, total: 7
//│ UERR 1 errors
//│ L: 1 [bool ~ int, bool <: α121', [α121' - list[[α121']] ~ list[[int]] - int, L: 0 [list[[α121']] ~ list[[int]], list[[α121']] <: α120', α120' :> list[[int]]]]]
262 changes: 131 additions & 131 deletions shared/src/test/diff/ocaml/OcamlComparison.mls

Large diffs are not rendered by default.

1,510 changes: 749 additions & 761 deletions shared/src/test/diff/ocaml/OcamlDataset.mls

Large diffs are not rendered by default.

82 changes: 24 additions & 58 deletions shared/src/test/diff/ocaml/OcamlExprChecker.mls
Original file line number Diff line number Diff line change
@@ -177,35 +177,23 @@ type ('a, 'b) heapD = HeapD of 'a * 'b list
(("hi", 1) :: Nil)
(("hi", 1) :: Nil):heap
(("hi", 1) :: ("bye", 2) :: Nil):heap
//│ [ERROR] Type `_ list` does not match `heap`
//│ [ERROR] Type `(string * int) list` does not match `heap`
//│
//│ (_ list) ---> (heap)
//│ ((string * int) list) ---> (heap)
//│
//│ ◉ (_ list) comes from
//│ ◉ ((string * int) list) comes from
//│ │ - l.2 (("hi", 1) :: Nil):heap
//│ │ ^^^^^^^^^^^^^^^^^^
//│ ▼
//│ ◉ (heap) comes from
//│ - l.2 (("hi", 1) :: Nil):heap
//│ ^^^^
//│ [ERROR] Type `_ list` does not match `heap`
//│
//│ (_ list) ---> (heap)
//│
//│ ◉ (_ list) comes from
//│ │ - l.3 (("hi", 1) :: ("bye", 2) :: Nil):heap
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//│ ▼
//│ ◉ (heap) comes from
//│ - l.3 (("hi", 1) :: ("bye", 2) :: Nil):heap
//│ ^^^^
//│ res: list[(string, int,)]
//│ res: heap
//│ res: heap
//│ U max: 3, total: 25
//│ UERR 2 errors
//│ L: 0 [list['a123] ~ heap, list['a123] <: heap]
//│ L: 0 [list['a121] ~ heap, list['a121] <: heap]
//│ U max: 2, total: 6
//│ UERR 1 errors
//│ L: 0 [list[([[string]], [[int]],)] ~ heap, list[([[string]], [[int]],)] <: heap]

let update h str i = (str,i)::h
//│ update: list[('a, 'b,)] -> 'a -> 'b -> list[('a, 'b,)]
@@ -229,21 +217,21 @@ let interp2 = (fun (env:env) opt ->
//│ ^^^^
//│ ╔══[ERROR] Unsupported pattern shape:
//│ ║
//│ ║ l.215: fun (env: env) _ -> []
//│ ║ l.203: fun (env: env) _ -> []
//│ ╙── ^^^^^^^^^^^^
//│ res: err -> list['a]
//│ ╔══[ERROR] Unsupported pattern shape:
//│ ║
//│ ║ l.216: let interp2 = (fun (env:env) opt ->
//│ ║ l.204: let interp2 = (fun (env:env) opt ->
//│ ╙── ^^^^^^^^^^^^^
//│ ╔══[ERROR] identifier not found: opt
//│ ║
//│ ║ l.217: match opt with
//│ ║ l.205: match opt with
//│ ╙── ^^^
//│ interp2: err -> int
//│ U max: 1, total: 2
//│ UERR 1 errors
//│ L: 0 [err ~ option['a132'], err <: option['a132']]
//│ L: 0 [err ~ option['a99'], err <: option['a99']]

let head xs = match xs with
Cons(x, xs) -> x
@@ -305,7 +293,7 @@ let checkagain (v: (int, int, (int, int))) =
//│ │ ^
//│ ▼
//│ ◉ (int) comes from
//│ - l.-223let (+): int -> int -> int
//│ - l.-211let (+): int -> int -> int
//│ ^^^
//│ [ERROR] Type `int` does not match `err`
//│
@@ -344,24 +332,24 @@ let checkagain (v: (int, int, (int, int))) =
//│ ^
//│ ╔══[ERROR] identifier not found: k
//│ ║
//│ ║ l.298: (a, b, (k, d)) -> a + b + k + d
//│ ║ l.286: (a, b, (k, d)) -> a + b + k + d
//│ ╙── ^
//│ ╔══[ERROR] identifier not found: d
//│ ║
//│ ║ l.298: (a, b, (k, d)) -> a + b + k + d
//│ ║ l.286: (a, b, (k, d)) -> a + b + k + d
//│ ╙── ^
//│ ╔══[ERROR] identifier not found: k
//│ ║
//│ ║ l.298: (a, b, (k, d)) -> a + b + k + d
//│ ║ l.286: (a, b, (k, d)) -> a + b + k + d
//│ ╙── ^
//│ ╔══[ERROR] identifier not found: d
//│ ║
//│ ║ l.298: (a, b, (k, d)) -> a + b + k + d
//│ ║ l.286: (a, b, (k, d)) -> a + b + k + d
//│ ╙── ^
//│ checkagain: (int, int, (int, int,),) -> int
//│ U max: 3, total: 15
//│ UERR 2 errors
//│ L: 2 [int ~ err, [int - ([int], [int],) ~ ([[err]], [[err]],) - err, L: 1 [([int], [int],) ~ ([[err]], [[err]],), [([int], [int],) - ([int], [int], [([int], [int],)],) ~ ([α157'], [α158'], [α159'],) - α159', L: 0 [([int], [int], [([int], [int],)],) ~ ([α157'], [α158'], [α159'],), ([int], [int], [([int], [int],)],) :> α155', α155' <: ([α157'], [α158'], [α159'],)]], α159' <: ([[err]], [[err]],)]]]
//│ L: 2 [int ~ err, [int - ([int], [int],) ~ ([[err]], [[err]],) - err, L: 1 [([int], [int],) ~ ([[err]], [[err]],), [([int], [int],) - ([int], [int], [([int], [int],)],) ~ ([α124'], [α125'], [α126'],) - α126', L: 0 [([int], [int], [([int], [int],)],) ~ ([α124'], [α125'], [α126'],), ([int], [int], [([int], [int],)],) :> α122', α122' <: ([α124'], [α125'], [α126'],)]], α126' <: ([[err]], [[err]],)]]]
//│ L: 0 [err ~ int, err <: int]

let (<): 'a -> 'a -> bool
@@ -412,47 +400,25 @@ let g x = x, if true then x else x
[0, 1; 2, 3, 4]
//│ [ERROR] Type `int * int * int` does not match `int * int`
//│
//│ (int * int * int) ~~~~ (?a0) ~~~~ (?a) ~~~~ (int * int)
//│ (int * int * int) ~~~~ (int * int)
//│
//│ ◉ (int * int * int) comes from
//│ - l.1 [0, 1; 2, 3, 4]
//│ ^^^^^^^
//│ ◉ ((int * int * int) * _ list) comes from
//│ ◉ ((int * int * int) list) comes from
//│ │ - l.1 [0, 1; 2, 3, 4]
//│ │ ^^^^^^^
//│ ▼
//│ ◉ (?a0 * ?a0 list) comes from
//│ ◉ ((int * int) list) comes from
//│ - l.1 [0, 1; 2, 3, 4]
//│ ^^^^^^^
//│ ◉ (?a0) is assumed for
//│ ◉ (?a0 list) comes from
//│ - l.1 [0, 1; 2, 3, 4]
//│ ^^^^^^^
//│ ◉ ((int * int) * ?a0 list) comes from
//│ │ - l.1 [0, 1; 2, 3, 4]
//│ │ ^^^^^^^^^^^^^
//│ ▼
//│ ◉ (?a * ?a list) comes from
//│ - l.1 [0, 1; 2, 3, 4]
//│ ^^^^^^^^^^^^^
//│ ◉ (?a list) comes from
//│ ◉ (?a) is assumed for
//│ ◉ (?a * ?a list) comes from
//│ ▲ - l.1 [0, 1; 2, 3, 4]
//│ │ ^^^^^^^^^^^^^
//│ │
//│ ◉ ((int * int) * ?a0 list) comes from
//│ - l.1 [0, 1; 2, 3, 4]
//│ ^^^^^^^^^^^^^
//│ ^^^^^^^^^^^^^^^
//│ ◉ (int * int) comes from
//│ - l.1 [0, 1; 2, 3, 4]
//│ ^^^^
//│ res: list['a]
//│ where
//│ 'a = (int, int, int,), (int, int,)
//│ U max: 3, total: 15
//│ res: list[(int, int,)]
//│ U max: 1, total: 3
//│ UERR 1 errors
//│ L: 2 [([[int]], [[int]], [[int]],) ~ ([[int]], [[int]],), [([[int]], [[int]], [[int]],) - ([([[int]], [[int]], [[int]],)], [[list['a191]]],) ~ ('a190, list['a190],) - 'a190, L: 0 [([([[int]], [[int]], [[int]],)], [[list['a191]]],) ~ ('a190, list['a190],), ([([[int]], [[int]], [[int]],)], [[list['a191]]],) <: ('a190, list['a190],)]], ['a190 - list['a190] ~ list['a189] - 'a189, L: 1 [list['a190] ~ list['a189], [list['a190] - ([([[int]], [[int]],)], [[list['a190]]],) ~ ('a189, list['a189],) - list['a189], L: 0 [([([[int]], [[int]],)], [[list['a190]]],) ~ ('a189, list['a189],), ([([[int]], [[int]],)], [[list['a190]]],) <: ('a189, list['a189],)]]]], ['a189 - ('a189, list['a189],) ~ ([([[int]], [[int]],)], [[list['a190]]],) - ([[int]], [[int]],), L: 0 [('a189, list['a189],) ~ ([([[int]], [[int]],)], [[list['a190]]],), ('a189, list['a189],) :> ([([[int]], [[int]],)], [[list['a190]]],)]]]
//│ L: 1 [([[int]], [[int]], [[int]],) ~ ([[int]], [[int]],), [([[int]], [[int]], [[int]],) - list[([[int]], [[int]], [[int]],)] ~ list[([[int]], [[int]],)] - ([[int]], [[int]],), L: 0 [list[([[int]], [[int]], [[int]],)] ~ list[([[int]], [[int]],)], list[([[int]], [[int]], [[int]],)] <: list[([[int]], [[int]],)]]]]

let increment x = match x with
| 0 -> 1
@@ -497,5 +463,5 @@ let len ls = match ls with | "hd :: tl" -> 1 | [] -> 0
//│ 'b = list['a], string
//│ U max: 1, total: 4
//│ UERR 1 errors
//│ L: 0 [string ~ list['a207'], string :> α205', α205' <: list['a207']]
//│ L: 0 [string ~ list['a162'], string :> α160', α160' <: list['a162']]

153 changes: 8 additions & 145 deletions shared/src/test/diff/ocaml/OcamlPresentation.mls
Original file line number Diff line number Diff line change
@@ -301,46 +301,7 @@ let wrap x = x :: []
let rec t = wrap (if true then 1 else t)
//│ [ERROR] Type `_ list` does not match `int`
//│
//│ (_ list) ---> (?t) ---> (?b) ---> (?a) <--- (?b) <--- (int)
//│
//│ ◉ (_ list) comes from
//│ │ - l.1 let wrap x = x :: []
//│ │ ^^^^^^^
//│ │ - l.2 let rec t = wrap (if true then 1 else t)
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//│ │ - l.2 let rec t = wrap (if true then 1 else t)
//│ │ ^
//│ ▼
//│ ◉ (?t) is assumed for
//│ │ - l.2 let rec t = wrap (if true then 1 else t)
//│ │ ^
//│ │ - l.2 let rec t = wrap (if true then 1 else t)
//│ │ ^
//│ │ - l.2 let rec t = wrap (if true then 1 else t)
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^
//│ ▼
//│ ◉ (?b) is assumed for
//│ │ - l.2 let rec t = wrap (if true then 1 else t)
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^
//│ │ - l.1 let wrap x = x :: []
//│ │ ^
//│ ▼
//│ ◉ (?a) is assumed for
//│ ▲ - l.1 let wrap x = x :: []
//│ │ ^
//│ │ - l.2 let rec t = wrap (if true then 1 else t)
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^
//│ │
//│ ◉ (?b) is assumed for
//│ ▲ - l.2 let rec t = wrap (if true then 1 else t)
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^
//│ │
//│ ◉ (int) comes from
//│ - l.2 let rec t = wrap (if true then 1 else t)
//│ ^
//│ [ERROR] Type `_ list` does not match `int`
//│
//│ (?a list) ---> (?t) ---> (?c) ---> (?b) ~~~~ (?a) ~~~~ (?b) <--- (?c) <--- (int)
//│ (?a list) ---> (?t) ---> (?b) ---> (?a) <--- (?b) <--- (int)
//│
//│ ◉ (?a list) comes from
//│ │ - l.1 let wrap x = x :: []
@@ -358,108 +319,13 @@ let rec t = wrap (if true then 1 else t)
//│ │ - l.2 let rec t = wrap (if true then 1 else t)
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^
//│ ▼
//│ ◉ (?c) is assumed for
//│ │ - l.2 let rec t = wrap (if true then 1 else t)
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^
//│ ▼
//│ ◉ (?b) is assumed for
//│ - l.1 let wrap x = x :: []
//│ ^
//│ ◉ (?b * _ list) comes from
//│ │ - l.1 let wrap x = x :: []
//│ │ ^^^^^^^
//│ ▼
//│ ◉ (?a * ?a list) comes from
//│ - l.1 let wrap x = x :: []
//│ ^^^^^^^
//│ ◉ (?a) is assumed for
//│ ◉ (?a * ?a list) comes from
//│ ▲ - l.1 let wrap x = x :: []
//│ │ ^^^^^^^
//│ │
//│ ◉ (?b * _ list) comes from
//│ - l.1 let wrap x = x :: []
//│ ^^^^^^^
//│ ◉ (?b) is assumed for
//│ ▲ - l.1 let wrap x = x :: []
//│ │ ^
//│ │ - l.2 let rec t = wrap (if true then 1 else t)
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^
//│ │
//│ ◉ (?c) is assumed for
//│ ▲ - l.2 let rec t = wrap (if true then 1 else t)
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^
//│ │
//│ ◉ (int) comes from
//│ - l.2 let rec t = wrap (if true then 1 else t)
//│ ^
//│ [ERROR] Type `_ list` does not match `int`
//│
//│ (?a0 list) ---> (?t) ---> (?b) ---> (?c) ~~~~ (?a0) ~~~~ (?a) ~~~~ (?a0) ~~~~ (?c) <--- (?b) <--- (int)
//│
//│ ◉ (?a0 list) comes from
//│ │ - l.1 let wrap x = x :: []
//│ │ ^^^^^^^
//│ │ - l.2 let rec t = wrap (if true then 1 else t)
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//│ │ - l.2 let rec t = wrap (if true then 1 else t)
//│ │ ^
//│ ▼
//│ ◉ (?t) is assumed for
//│ │ - l.2 let rec t = wrap (if true then 1 else t)
//│ │ ^
//│ │ - l.2 let rec t = wrap (if true then 1 else t)
//│ │ ^
//│ │ - l.2 let rec t = wrap (if true then 1 else t)
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^
//│ ▼
//│ ◉ (?b) is assumed for
//│ │ - l.2 let rec t = wrap (if true then 1 else t)
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^
//│ │ ^
//│ ▼
//│ ◉ (?c) is assumed for
//│ - l.1 let wrap x = x :: []
//│ ^
//│ ◉ (?c * ?a list) comes from
//│ │ - l.1 let wrap x = x :: []
//│ │ ^^^^^^^
//│ ▼
//│ ◉ (?a0 * ?a0 list) comes from
//│ - l.1 let wrap x = x :: []
//│ ^^^^^^^
//│ ◉ (?a0) is assumed for
//│ ◉ (?a0 list) comes from
//│ ◉ (?a0 * ?a0 list) comes from
//│ ▲ - l.1 let wrap x = x :: []
//│ │ ^^^^^^^
//│ │
//│ ◉ (?c * ?a list) comes from
//│ - l.1 let wrap x = x :: []
//│ ^^^^^^^
//│ ◉ (?a list) comes from
//│ - l.1 let wrap x = x :: []
//│ ^^
//│ ◉ (?a) is assumed for
//│ ◉ (?a list) comes from
//│ - l.1 let wrap x = x :: []
//│ ^^
//│ ◉ (?c * ?a list) comes from
//│ │ - l.1 let wrap x = x :: []
//│ │ ^^^^^^^
//│ ▼
//│ ◉ (?a0 * ?a0 list) comes from
//│ - l.1 let wrap x = x :: []
//│ ^^^^^^^
//│ ◉ (?a0 list) comes from
//│ ◉ (?a0) is assumed for
//│ ◉ (?a0 * ?a0 list) comes from
//│ ▲ - l.1 let wrap x = x :: []
//│ │ ^^^^^^^
//│ │
//│ ◉ (?c * ?a list) comes from
//│ - l.1 let wrap x = x :: []
//│ ^^^^^^^
//│ ◉ (?c) is assumed for
//│ ▲ - l.1 let wrap x = x :: []
//│ │ ^
//│ │ - l.2 let rec t = wrap (if true then 1 else t)
@@ -475,13 +341,10 @@ let rec t = wrap (if true then 1 else t)
//│ wrap: 'a -> list['a]
//│ t: 't
//│ where
//│ 't = list['a], int
//│ 'a = list['a], int
//│ U max: 5, total: 41
//│ UERR 3 errors
//│ L: 2 [list['a84'] ~ int, list['a84'] <: t82', t82' <: α86', α86' <: α83', [α83' - ([[α83']], [[list['a85']]],) ~ ('a84', list['a84'],) - 'a84', L: 0 [([[α83']], [[list['a85']]],) ~ ('a84', list['a84'],), ([[α83']], [[list['a85']]],) <: ('a84', list['a84'],)]], ['a84' - list['a84'] ~ list['a85'] - 'a85', L: 1 [list['a84'] ~ list['a85'], [list['a84'] - ('a84', list['a84'],) ~ ([[α83']], [[list['a85']]],) - list['a85'], L: 0 [('a84', list['a84'],) ~ ([[α83']], [[list['a85']]],), ('a84', list['a84'],) :> ([[α83']], [[list['a85']]],)]]]], ['a85' - list['a85'] ~ list['a84'] - 'a84', L: 1 [list['a85'] ~ list['a84'], [list['a85'] - ([[α83']], [[list['a85']]],) ~ ('a84', list['a84'],) - list['a84'], L: 0 [([[α83']], [[list['a85']]],) ~ ('a84', list['a84'],), ([[α83']], [[list['a85']]],) <: ('a84', list['a84'],)]]]], ['a84' - ('a84', list['a84'],) ~ ([[α83']], [[list['a85']]],) - α83', L: 0 [('a84', list['a84'],) ~ ([[α83']], [[list['a85']]],), ('a84', list['a84'],) :> ([[α83']], [[list['a85']]],)]], α83' :> α86', α86' :> int]
//│ L: 1 [list['a84'] ~ int, list['a84'] <: t82', t82' <: α86', α86' <: α83', [α83' - ([[α83']], [[list['a85']]],) ~ ('a84', list['a84'],) - 'a84', L: 0 [([[α83']], [[list['a85']]],) ~ ('a84', list['a84'],), ([[α83']], [[list['a85']]],) <: ('a84', list['a84'],)]], ['a84' - ('a84', list['a84'],) ~ ([[α83']], [[list['a85']]],) - α83', L: 0 [('a84', list['a84'],) ~ ([[α83']], [[list['a85']]],), ('a84', list['a84'],) :> ([[α83']], [[list['a85']]],)]], α83' :> α86', α86' :> int]
//│ L: 0 [list['a84'] ~ int, list['a84'] <: t82', t82' <: α86', α86' <: α83', α83' :> α86', α86' :> int]
//│ 't = list['t], int
//│ U max: 3, total: 11
//│ UERR 1 errors
//│ L: 0 [list[[α80']] ~ int, list[[α80']] <: t79', t79' <: α81', α81' <: α80', α80' :> α81', α81' :> int]


let rec length ls = match ls with | hd :: tl -> 1 + length tl | [] -> 0
@@ -521,7 +384,7 @@ let weird x = (x + 1, length x)
//│ 'b = list['a], int
//│ U max: 4, total: 29
//│ UERR 1 errors
//│ L: 1 [list['a98'] ~ int, [list['a98'] - ([list['a98']] -> α100') ~ ([α95'] -> α101') - α95', L: 0 [([list['a98']] -> α100') ~ ([α95'] -> α101'), ([list['a98']] -> α100') :> length96', length96' <: ([α95'] -> α101')]], α95' <: int]
//│ L: 1 [list['a92'] ~ int, [list['a92'] - ([list['a92']] -> α94') ~ ([α89'] -> α95') - α89', L: 0 [([list['a92']] -> α94') ~ ([α89'] -> α95'), ([list['a92']] -> α94') :> length90', length90' <: ([α89'] -> α95')]], α89' <: int]


let len ls = match ls with | "hd :: tl" -> 1 | [] -> 0
@@ -551,4 +414,4 @@ let len ls = match ls with | "hd :: tl" -> 1 | [] -> 0
//│ 'b = list['a], string
//│ U max: 1, total: 4
//│ UERR 1 errors
//│ L: 0 [string ~ list['a106'], string :> α104', α104' <: list['a106']]
//│ L: 0 [string ~ list['a100'], string :> α98', α98' <: list['a100']]
7,503 changes: 5,290 additions & 2,213 deletions shared/src/test/diff/ocaml/Regression.mls

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion shared/src/test/diff/ocaml/SurveyHard2.mls
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ let bigAdd l1 l2 =
//│ ◉ (_ * _) comes from
//│ - l.14 let (_,res) = List.fold_left f base args in res in
//│ ^^^^^^^
//│ U max: 63, total: 470
//│ U max: 63, total: 468
//│ UERR 3 errors
//│ L: 2 [int ~ ([α127''], [α128''],), [int - (α123'' -> [int]) ~ (α121'' -> α120'') - α120'', L: 1 [(α123'' -> [int]) ~ (α121'' -> α120''), [(α123'' -> [int]) - (α122'' -> (α123'' -> [int])) ~ (α120'' -> (α121'' -> α120'')) - (α121'' -> α120''), L: 0 [(α122'' -> (α123'' -> [int])) ~ (α120'' -> (α121'' -> α120'')), (α122'' -> (α123'' -> [int])) <: (α120'' -> (α121'' -> α120''))]]]], α120'' <: ([α127''], [α128''],)]
//│ L: 1 [int ~ ([α127''], [α128''],), int :> α122'', [α122'' - (α122'' -> (α123'' -> [int])) ~ (α120'' -> (α121'' -> α120'')) - α120'', L: 0 [(α122'' -> (α123'' -> [int])) ~ (α120'' -> (α121'' -> α120'')), (α122'' -> (α123'' -> [int])) <: (α120'' -> (α121'' -> α120''))]], α120'' <: ([α127''], [α128''],)]
6 changes: 3 additions & 3 deletions shared/src/test/diff/ocaml/SurveyHard3.mls
Original file line number Diff line number Diff line change
@@ -181,9 +181,9 @@ let bigAdd l1 l2 =
//│ ◉ (_ * _) comes from
//│ - l.22 (let (toSum1,toSum2) = x in
//│ ^^^^^^^^^^^^^^^
//│ U max: 35, total: 551
//│ U max: 33, total: 532
//│ UERR 3 errors
//│ L: 2 [([α127''], [α128''],) ~ list['a139''], [([α127''], [α128''],) - list[([α127''], [α128''],)] ~ list[α145''] - α145'', L: 0 [list[([α127''], [α128''],)] ~ list[α145''], list[([α127''], [α128''],)] <: list[α145'']]], [α145'' - list[α145''] ~ list[α130''] - α130'', L: 0 [list[α145''] ~ list[α130''], list[α145''] <: list[α130'']]], [α130'' - (α130'' -> α129'') ~ (α136'' -> α141'') - α136'', L: 1 [(α130'' -> α129'') ~ (α136'' -> α141''), [(α130'' -> α129'') - (α129'' -> (α130'' -> α129'')) ~ (α131'' -> (α136'' -> α141'')) - (α136'' -> α141''), L: 0 [(α129'' -> (α130'' -> α129'')) ~ (α131'' -> (α136'' -> α141'')), (α129'' -> (α130'' -> α129'')) :> (α131'' -> (α136'' -> α141''))]]]], α136'' <: α140'', α140'' :> list['a139'']]
//│ L: 2 [list['a139''] ~ ([α137''], [α138''],), list['a139''] <: α140'', α140'' :> α136'', [α136'' - (α136'' -> α141'') ~ (α130'' -> α129'') - α130'', L: 1 [(α136'' -> α141'') ~ (α130'' -> α129''), [(α136'' -> α141'') - (α131'' -> (α136'' -> α141'')) ~ (α129'' -> (α130'' -> α129'')) - (α130'' -> α129''), L: 0 [(α131'' -> (α136'' -> α141'')) ~ (α129'' -> (α130'' -> α129'')), (α131'' -> (α136'' -> α141'')) <: (α129'' -> (α130'' -> α129''))]]]], [α130'' - (α130'' -> α129'') ~ (α136'' -> α141'') - α136'', L: 1 [(α130'' -> α129'') ~ (α136'' -> α141''), [(α130'' -> α129'') - (α129'' -> (α130'' -> α129'')) ~ (α131'' -> (α136'' -> α141'')) - (α136'' -> α141''), L: 0 [(α129'' -> (α130'' -> α129'')) ~ (α131'' -> (α136'' -> α141'')), (α129'' -> (α130'' -> α129'')) :> (α131'' -> (α136'' -> α141''))]]]], α136'' <: ([α137''], [α138''],)]
//│ L: 2 [([α127''], [α128''],) ~ list['a141''], [([α127''], [α128''],) - list[([α127''], [α128''],)] ~ list[α144''] - α144'', L: 0 [list[([α127''], [α128''],)] ~ list[α144''], list[([α127''], [α128''],)] <: list[α144'']]], [α144'' - list[α144''] ~ list[α130''] - α130'', L: 0 [list[α144''] ~ list[α130''], list[α144''] <: list[α130'']]], [α130'' - (α130'' -> α129'') ~ (α138'' -> α135'') - α138'', L: 1 [(α130'' -> α129'') ~ (α138'' -> α135''), [(α130'' -> α129'') - (α129'' -> (α130'' -> α129'')) ~ (α131'' -> (α138'' -> α135'')) - (α138'' -> α135''), L: 0 [(α129'' -> (α130'' -> α129'')) ~ (α131'' -> (α138'' -> α135'')), (α129'' -> (α130'' -> α129'')) :> (α131'' -> (α138'' -> α135''))]]]], α138'' <: α142'', α142'' :> list['a141'']]
//│ L: 2 [list['a141''] ~ ([α139''], [α140''],), list['a141''] <: α142'', α142'' :> α138'', [α138'' - (α138'' -> α135'') ~ (α130'' -> α129'') - α130'', L: 1 [(α138'' -> α135'') ~ (α130'' -> α129''), [(α138'' -> α135'') - (α131'' -> (α138'' -> α135'')) ~ (α129'' -> (α130'' -> α129'')) - (α130'' -> α129''), L: 0 [(α131'' -> (α138'' -> α135'')) ~ (α129'' -> (α130'' -> α129'')), (α131'' -> (α138'' -> α135'')) <: (α129'' -> (α130'' -> α129''))]]]], [α130'' - (α130'' -> α129'') ~ (α138'' -> α135'') - α138'', L: 1 [(α130'' -> α129'') ~ (α138'' -> α135''), [(α130'' -> α129'') - (α129'' -> (α130'' -> α129'')) ~ (α131'' -> (α138'' -> α135'')) - (α138'' -> α135''), L: 0 [(α129'' -> (α130'' -> α129'')) ~ (α131'' -> (α138'' -> α135'')), (α129'' -> (α130'' -> α129'')) :> (α131'' -> (α138'' -> α135''))]]]], α138'' <: ([α139''], [α140''],)]
//│ L: 0 [list['a118'''] ~ ([α122'''], [α123'''],), list['a118'''] <: α117''', α117''' :> α113''', α113''' <: ([α122'''], [α123'''],)]

1,150 changes: 708 additions & 442 deletions shared/src/test/diff/ocaml/SurveyMed1.mls

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions shared/src/test/diff/ocaml/SurveyMed2.mls
Original file line number Diff line number Diff line change
@@ -29,11 +29,11 @@ let rec mulByDigit i l =
//│ ◉ (int) comes from
//│ - lib. let ( * ): int -> int -> int
//│ ^^^
//│ [ERROR] Type `_ list` does not match `int`
//│ [ERROR] Type `int list` does not match `int`
//│
//│ (_ list) ---> (?a) ---> (int)
//│ (int list) ---> (?a) ---> (int)
//│
//│ ◉ (_ list) comes from
//│ ◉ (int list) comes from
//│ │ - l.5 let y = [1; 2; 3]
//│ │ ^^^^^^^^^
//│ │ - l.10 | h::t -> [remainder strings_of y] @ (mulByDigit i t)
@@ -50,8 +50,8 @@ let rec mulByDigit i l =
//│ ◉ (int) comes from
//│ - lib. let ( * ): int -> int -> int
//│ ^^^
//│ U max: 7, total: 100
//│ U max: 5, total: 58
//│ UERR 2 errors
//│ L: 0 [list['a69'] ~ int, list['a69'] <: α64', α64' <: int]
//│ L: 0 [(α66' -> [(list[α67'] -> list[α68'])]) ~ int, (α66' -> [(list[α67'] -> list[α68'])]) <: α63', α63' <: int]
//│ L: 0 [(α62' -> [(list[α63'] -> list[α64'])]) ~ int, (α62' -> [(list[α63'] -> list[α64'])]) <: α59', α59' <: int]
//│ L: 0 [list[[int]] ~ int, list[[int]] <: α60', α60' <: int]

10 changes: 5 additions & 5 deletions shared/src/test/diff/ocaml/SurveyMed3.mls
Original file line number Diff line number Diff line change
@@ -15,23 +15,23 @@ let rec additivePersistence n =
(* (@): 'a list -> 'a list -> 'a list is a list concatenation operator *)
//│ [ERROR] Type `bool` does not match `int`
//│
//│ (bool) ---> (?a) ---> (?b) <--- (int)
//│ (bool) ---> (?b) ---> (?a) <--- (int)
//│
//│ ◉ (bool) comes from
//│ │ - l.13 | h::t -> if (addNumbs (h :: t)) >= 10 then false else true
//│ │ ^^^^^
//│ │ - l.13 | h::t -> if (addNumbs (h :: t)) >= 10 then false else true
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//│ ▼
//│ ◉ (?a) is assumed for
//│ ◉ (?b) is assumed for
//│ │ - l.13 | h::t -> if (addNumbs (h :: t)) >= 10 then false else true
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//│ │ - l.11 match digits n with
//│ │ ^^^^^^^^^^^^^^^^^^^
//│ │ | [] -> 0 ...
//│ │ ^^^^^^^^^^^^^
//│ ▼
//│ ◉ (?b) is assumed for
//│ ◉ (?a) is assumed for
//│ ▲ - l.11 match digits n with
//│ │ ^^^^^^^^^^^^^^^^^^^
//│ │ | [] -> 0 ...
@@ -40,6 +40,6 @@ let rec additivePersistence n =
//│ ◉ (int) comes from
//│ - l.12 | [] -> 0
//│ ^
//│ U max: 6, total: 137
//│ U max: 5, total: 115
//│ UERR 1 errors
//│ L: 0 [bool ~ int, bool <: α96', α96' <: α86', α86' :> int]
//│ L: 0 [bool ~ int, bool <: α90', α90' <: α80', α80' :> int]
34 changes: 17 additions & 17 deletions shared/src/test/diff/ocaml/TupleLists.mls
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@


let f = if true then [0, 1] else [0], [1]
//│ [ERROR] Type `_ list * _ list` does not match `_ list`
//│ [ERROR] Type `int list * int list` does not match `(int * int) list`
//│
//│ (_ list * _ list) ---> (?a) <--- (_ list)
//│ (int list * int list) ---> (?a) <--- ((int * int) list)
//│
//│ ◉ (_ list * _ list) comes from
//│ ◉ (int list * int list) comes from
//│ │ - l.1 let f = if true then [0, 1] else [0], [1]
//│ │ ^^^^^^^^
//│ │ - l.1 let f = if true then [0, 1] else [0], [1]
@@ -15,22 +15,22 @@ let f = if true then [0, 1] else [0], [1]
//│ ▲ - l.1 let f = if true then [0, 1] else [0], [1]
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//│ │
//│ ◉ (_ list) comes from
//│ ◉ ((int * int) list) comes from
//│ - l.1 let f = if true then [0, 1] else [0], [1]
//│ ^^^^^^
//│ f: 'a
//│ where
//│ 'a = (list[int], list[int],), list[(int, int,)]
//│ U max: 2, total: 16
//│ U max: 1, total: 4
//│ UERR 1 errors
//│ L: 0 [([[list['a45']]], [[list['a47']]],) ~ list['a43'], ([[list['a45']]], [[list['a47']]],) <: α42', α42' :> list['a43']]
//│ L: 0 [([list[[int]]], [list[[int]]],) ~ list[([[int]], [[int]],)], ([list[[int]]], [list[[int]]],) <: α42', α42' :> list[([[int]], [[int]],)]]

let f x = if true then [0, 1] else x, [1]
//│ [ERROR] Type `_ * _ list` does not match `_ list`
//│ [ERROR] Type `_ * int list` does not match `(int * int) list`
//│
//│ (_ * _ list) ---> (?a) <--- (_ list)
//│ (_ * int list) ---> (?a) <--- ((int * int) list)
//│
//│ ◉ (_ * _ list) comes from
//│ ◉ (_ * int list) comes from
//│ │ - l.1 let f x = if true then [0, 1] else x, [1]
//│ │ ^^^^^^
//│ │ - l.1 let f x = if true then [0, 1] else x, [1]
@@ -40,25 +40,25 @@ let f x = if true then [0, 1] else x, [1]
//│ ▲ - l.1 let f x = if true then [0, 1] else x, [1]
//│ │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//│ │
//│ ◉ (_ list) comes from
//│ ◉ ((int * int) list) comes from
//│ - l.1 let f x = if true then [0, 1] else x, [1]
//│ ^^^^^^
//│ f: 'a -> 'b
//│ where
//│ 'b = ('a, list[int],), list[(int, int,)]
//│ U max: 2, total: 12
//│ U max: 1, total: 4
//│ UERR 1 errors
//│ L: 0 [([[α52']], [[list['a56']]],) ~ list['a54'], ([[α52']], [[list['a56']]],) <: α53', α53' :> list['a54']]
//│ L: 0 [([[α43']], [list[[int]]],) ~ list[([[int]], [[int]],)], ([[α43']], [list[[int]]],) <: α44', α44' :> list[([[int]], [[int]],)]]

let test: (int * int) list
//│ test: list[(int, int,)]

let f x = if true then test else x, [1]
//│ [ERROR] Type `_ * _ list` does not match `(int * int) list`
//│ [ERROR] Type `_ * int list` does not match `(int * int) list`
//│
//│ (_ * _ list) ---> (?a) <--- ((int * int) list)
//│ (_ * int list) ---> (?a) <--- ((int * int) list)
//│
//│ ◉ (_ * _ list) comes from
//│ ◉ (_ * int list) comes from
//│ │ - l.1 let f x = if true then test else x, [1]
//│ │ ^^^^^^
//│ │ - l.1 let f x = if true then test else x, [1]
@@ -76,7 +76,7 @@ let f x = if true then test else x, [1]
//│ f: 'a -> 'b
//│ where
//│ 'b = ('a, list[int],), list[(int, int,)]
//│ U max: 2, total: 8
//│ U max: 1, total: 4
//│ UERR 1 errors
//│ L: 0 [([[α60']], [[list['a62']]],) ~ list[([int], [int],)], ([[α60']], [[list['a62']]],) <: α61', α61' :> list[([int], [int],)]]
//│ L: 0 [([[α45']], [list[[int]]],) ~ list[([int], [int],)], ([[α45']], [list[[int]]],) <: α46', α46' :> list[([int], [int],)]]

0 comments on commit 25d752d

Please sign in to comment.