diff --git a/lib/parser.mly b/lib/parser.mly index b50c2346..eccc65ac 100644 --- a/lib/parser.mly +++ b/lib/parser.mly @@ -103,6 +103,7 @@ %left Plus_op %left Mult_op %left Dot Ampersand Exclamation +%left Lbrack %left Lpar %left Path Hashtag_brack @@ -192,7 +193,7 @@ record_item_decl: decl_typename: | name = Ident { { name; poly_param = [] } } - | name = Ident; Lpar; poly_param = separated_nonempty_list(Comma, poly_id); Rpar { { name; poly_param } } + | name = Ident; Lbrack; poly_param = separated_nonempty_list(Comma, poly_id); Rbrack { { name; poly_param } } %inline module_decl: | name = ident { let loc, name = name in loc, name, None } @@ -483,7 +484,7 @@ type_spec: | id = Sized_ident { Ty_id id } | id = Unknown_sized_ident { Ty_id id } | path = type_path { Ty_use_id ($loc, path) } - | head = type_spec; Lpar; tail = separated_nonempty_list(Comma, type_spec); Rpar + | head = type_spec; Lbrack; tail = separated_nonempty_list(Comma, type_spec); Rbrack { Ty_applied (head :: tail) } | Lpar; Rpar; Right_arrow; ret = type_spec; %prec Type_application { Ty_func ([Ty_id "unit", Dnorm; ret, Dnorm]) } diff --git a/lib/syntax_errors.messages b/lib/syntax_errors.messages index 2ba2eaad..32ae21c2 100644 --- a/lib/syntax_errors.messages +++ b/lib/syntax_errors.messages @@ -16,9 +16,9 @@ prog: Type With prog: Type Ident With - +Expecting square brackets for parameterized type -prog: Type Ident Lpar With +prog: Type Ident Lbrack With @@ -26,11 +26,11 @@ prog: External Ident Colon Quote With -prog: Type Ident Lpar Quote Ident With +prog: Type Ident Lbrack Quote Ident With -prog: Type Ident Lpar Quote Ident Comma With +prog: Type Ident Lbrack Quote Ident Comma With @@ -66,19 +66,23 @@ prog: External Ident Colon Lpar Rpar Right_arrow Ident With -prog: External Ident Colon Ident Lpar With +prog: External Ident Colon Ident Lbrack With -prog: External Ident Colon Ident Lpar Ident Rbrac +prog: External Ident Colon Ident Lbrack Ident Rbrac -prog: External Ident Colon Ident Lpar Ident Comma With +prog: External Ident Colon Ident Lbrack Ident Comma With -prog: External Ident Colon Lpar Ident Rbrac +prog: External Ident Colon Ident Lbrack Ident Rpar + + + +prog: External Ident Colon Lpar Ident Rbrack @@ -114,7 +118,7 @@ prog: External Ident Colon Lpar Ident Ampersand Comma With -prog: External Ident Colon Lpar Ident Ampersand Comma Ident Rbrac +prog: External Ident Colon Lpar Ident Ampersand Comma Ident Rbrack @@ -126,7 +130,7 @@ prog: External Ident Colon Lpar Ident Comma With -prog: External Ident Colon Lpar Ident Comma Ident Rbrac +prog: External Ident Colon Lpar Ident Comma Ident Rbrack @@ -150,7 +154,7 @@ prog: External Ident Colon Lpar Ident Comma Ident Comma With -prog: External Ident Colon Lpar Ident Comma Ident Comma Ident Rbrac +prog: External Ident Colon Lpar Ident Comma Ident Comma Ident Rbrack @@ -188,7 +192,7 @@ prog: Type Ident Equal Lbrac Ident Colon With prog: Type Ident Equal Lbrac Ident Colon Ident Rpar - +Expecting square brackets for parameterized type prog: Type Ident Equal Lbrac Ident Colon Ident Comma With @@ -210,7 +214,7 @@ prog: Type Ident Equal Ctor Lpar Int With -prog: Type Ident Equal Ctor Lpar Ident Rbrac +prog: Type Ident Equal Ctor Lpar Ident Rbrack @@ -218,6 +222,10 @@ prog: Type Ident Equal Ctor Lpar Ident Comma With +prog: Type Ident Equal Ctor Lpar Ident Comma Ident Rbrack + + + prog: Type Ident Equal Ctor Lpar Ident Rpar With @@ -228,7 +236,7 @@ prog: Type Ident Equal Ctor Hbar With prog: Type Ident Equal Ident Rpar - +Expecting square brackets for parameterized type prog: Signature With @@ -274,7 +282,7 @@ prog: Signature Colon Begin Type With -prog: Signature Colon Begin Type Ident Lpar Quote Ident Rpar With +prog: Signature Colon Begin Type Ident Lbrack Quote Ident Rbrack With @@ -390,7 +398,7 @@ prog: Fun Lpar Ident Colon With -prog: Fun Lpar Ident Colon Ident Rbrac +prog: Fun Lpar Ident Colon Ident Rbrack diff --git a/lib/typing/types.ml b/lib/typing/types.ml index 0ad535e7..043ac554 100644 --- a/lib/typing/types.ml +++ b/lib/typing/types.ml @@ -101,7 +101,7 @@ let string_of_type_raw get_name typ mname = | [] -> Path.(rm_name mname name |> show) | l -> let arg = String.concat ", " (List.map string_of_type l) in - Printf.sprintf "%s(%s)" Path.(rm_name mname name |> show) arg + Printf.sprintf "%s[%s]" Path.(rm_name mname name |> show) arg end | Qvar str | Tvar { contents = Unbound (str, _) } -> get_name str | Tfixed_array ({ contents = sz }, t) -> @@ -111,7 +111,7 @@ let string_of_type_raw get_name typ mname = | Known i -> string_of_int i | Linked iv -> size !iv in - sprintf "array#%s(%s)" (size sz) (string_of_type t) + sprintf "array#%s[%s]" (size sz) (string_of_type t) in string_of_type typ diff --git a/schmu-mode.el b/schmu-mode.el index 166e1d18..0fce9897 100644 --- a/schmu-mode.el +++ b/schmu-mode.el @@ -41,6 +41,10 @@ (rx symbol-start (group (seq (any lower ?_) (* (any word ?_)))) (* space) "(")) +(defconst schmu-type-param-pattern + (rx symbol-start (group (seq (any lower ?_) (* (any word ?_)))) + (* space) "[")) + (defconst schmu-module-pattern (rx symbol-start (or "module" "module type" "functor" "use") (1+ space) (group (seq (any word ?_) (* (any word ?_)))))) @@ -72,6 +76,7 @@ (,schmu-types-regexp . font-lock-type-face) (,schmu-variable-pattern 1 font-lock-variable-name-face) (, schmu-call-pattern 1 font-lock-function-name-face) + (, schmu-type-param-pattern 1 font-lock-type-face) (,schmu-upcase-pattern 1 font-lock-type-face) (,schmu-path-pattern 1 font-lock-type-face)) "Schmu keywords highlighting.") diff --git a/std/hashtbl.smu b/std/hashtbl.smu index 8ec9fc46..84b291d8 100644 --- a/std/hashtbl.smu +++ b/std/hashtbl.smu @@ -9,28 +9,28 @@ module type key: module type sig: type key - type t('value) - - val create : (int) -> t('value) - val length : (t('value)) -> int - val insert : (t('value)&, key!, 'value!) -> unit - val remove : (t('value)&, key) -> unit - val find : (t('value), key) -> option/t('value) - val find_map : (t('value), key, ('value) -> 'a) -> option/t('a) - val find_mut : (t('value)&, key, ('value&) -> unit) -> bool - val mem : (t('value), key) -> bool - val fold : (t('value), 'b!, ('b!, key, 'value) -> 'c) -> 'c - val clear : (t('value)&) -> unit - val to_array : (t('value)) -> array((key, 'value)) + type t['value] + + val create : (int) -> t['value] + val length : (t['value]) -> int + val insert : (t['value]&, key!, 'value!) -> unit + val remove : (t['value]&, key) -> unit + val find : (t['value], key) -> option/t['value] + val find_map : (t['value], key, ('value) -> 'a) -> option/t['a] + val find_mut : (t['value]&, key, ('value&) -> unit) -> bool + val mem : (t['value], key) -> bool + val fold : (t['value], 'b!, ('b!, key, 'value) -> 'c) -> 'c + val clear : (t['value]&) -> unit + val to_array : (t['value]) -> array[(key, 'value)] functor make : sig(m : key): use option use prelude type key = m/t - type item('a) = {key : m/t, value& : 'a, pathlen& : int} - type slot('a) = option/t(item('a)) - type t('a) = {data& : array(slot('a)), nitems& : int} + type item['a] = {key : m/t, value& : 'a, pathlen& : int} + type slot['a] = option/t[item['a]] + type t['a] = {data& : array[slot['a]], nitems& : int} fun rec power_2_above(x, n): if x >= n: x else: diff --git a/std/in_channel.smu b/std/in_channel.smu index 5e6fc1dd..882467cc 100644 --- a/std/in_channel.smu +++ b/std/in_channel.smu @@ -6,29 +6,29 @@ import string signature: type t - val open : (string/t) -> option/t(t) + val open : (string/t) -> option/t[t] val close : (t) -> unit -- high level interface - val with_open : (string/t, (t&) -> 'a) -> option/t('a) + val with_open : (string/t, (t&) -> 'a) -> option/t['a] val readall : (t&) -> string/t val lines : (t&, (string/t) -> unit) -> unit -- low level interface - type buf = array(u8) - val readbuf : (t&, buf&) -> option/t(int) - val readn : (t&, buf&, int) -> option/t(int) - val readline : (t&, buf&) -> option/t(int) - val readrem : (t&, buf&) -> option/t(int) + type buf = array[u8] + val readbuf : (t&, buf&) -> option/t[int] + val readn : (t&, buf&, int) -> option/t[int] + val readline : (t&, buf&) -> option/t[int] + val readrem : (t&, buf&) -> option/t[int] type file val of_file : (file) -> t -type file = raw_ptr(u8) +type file = raw_ptr[u8] -type t = {buf& : array#4096(u8), head& : int, unseen& : int, file : file} +type t = {buf& : array#4096[u8], head& : int, unseen& : int, file : file} -type cstr = raw_ptr(u8) +type cstr = raw_ptr[u8] external fread : (cstr, int, int, file) -> int external fopen : (cstr, cstr) -> file external fclose : (cstr) -> int diff --git a/std/option.smu b/std/option.smu index 9f43ebe0..8b7a85b6 100644 --- a/std/option.smu +++ b/std/option.smu @@ -1 +1 @@ -type t('a) = #some('a) | #none +type t['a] = #some('a) | #none diff --git a/std/std.smu b/std/std.smu index 1bc20171..cc412e08 100644 --- a/std/std.smu +++ b/std/std.smu @@ -14,7 +14,7 @@ let println = string/println let print = string/print let cstr = string/data -type option('a) = option/t('a) +type option['a] = option/t['a] -- prelude re-exports let char_equal = prelude/char_equal diff --git a/std/string.smu b/std/string.smu index d47e53c6..28db3ebf 100644 --- a/std/string.smu +++ b/std/string.smu @@ -3,7 +3,7 @@ import option import prelude signature: - type cstr = raw_ptr(u8) + type cstr = raw_ptr[u8] type t val len : (t) -> int @@ -12,18 +12,18 @@ signature: val hash : (t) -> int val equal: (t, t) -> bool val append : (t&, t) -> unit - val concat : (t, array(t)) -> t - val boyer_moore_horspool : (t, t) -> option/t(int) + val concat : (t, array[t]) -> t + val boyer_moore_horspool : (t, t) -> option/t[int] - val modify_buf : (t&, (array(u8)&) -> unit) -> unit - val of_array : (array(u8)!) -> t - val to_array : (t!) -> array(u8) - val of_fixed_array : (array#?(u8)) -> t + val modify_buf : (t&, (array[u8]&) -> unit) -> unit + val of_array : (array[u8]!) -> t + val to_array : (t!) -> array[u8] + val of_fixed_array : (array#?[u8]) -> t val println : (t) -> unit val print : (t) -> unit -type t = array(u8) +type t = array[u8] -- TODO use aliases fun len(str : t): array/length(str) @@ -45,7 +45,7 @@ fun hash(str): array/fold(str, !5381, fun (hash!, c): (hash * 33) + u8_to_int(c)) -external memcmp : (raw_ptr(u8), raw_ptr(u8), int) -> i32 +external memcmp : (raw_ptr[u8], raw_ptr[u8], int) -> i32 fun equal(l, r): if len(l) == len(r): @@ -103,17 +103,17 @@ fun modify_buf(str& : t, f): -- return type needs to be inferred as unit () -fun of_array(arr! : array(u8)): arr +fun of_array(arr! : array[u8]): arr fun to_array(str! : t): str -external memcpy : (raw_ptr(u8), raw_ptr(u8), int) -> unit +external memcpy : (raw_ptr[u8], raw_ptr[u8], int) -> unit -fun of_fixed_array(arr : array#?(u8)): +fun of_fixed_array(arr : array#?[u8]): let ret = array/create(__fixed_array_length(arr)) memcpy(array/data(ret), __fixed_array_data(arr), __fixed_array_length(arr)) ret -type file = raw_ptr(u8) +type file = raw_ptr[u8] external stdout : file external fwrite : (cstr, int, int, file) -> unit diff --git a/std/unsafe.smu b/std/unsafe.smu index 42c9b867..e8591c8e 100644 --- a/std/unsafe.smu +++ b/std/unsafe.smu @@ -1,14 +1,14 @@ signature: - val nullptr : () -> raw_ptr(u8) + val nullptr : () -> raw_ptr[u8] -- functions on raw pointers - val get : (raw_ptr('a), int) -> 'a - val +> : (raw_ptr('a), int) -> 'a - val at : (raw_ptr('a), int) -> raw_ptr('a) - val reinterpret : (raw_ptr('a)) -> raw_ptr('b) - val addr : ('a&) -> raw_ptr('a) - val funptr : ('a) -> raw_ptr(unit) - val clsptr : ('a) -> raw_ptr(unit) + val get : (raw_ptr['a], int) -> 'a + val +> : (raw_ptr['a], int) -> 'a + val at : (raw_ptr['a], int) -> raw_ptr['a] + val reinterpret : (raw_ptr['a]) -> raw_ptr['b] + val addr : ('a&) -> raw_ptr['a] + val funptr : ('a) -> raw_ptr[unit] + val clsptr : ('a) -> raw_ptr[unit] let nullptr = __unsafe_nullptr let get = __unsafe_ptr_get diff --git a/test/autogen.t/copy_array.smu b/test/autogen.t/copy_array.smu index 4b4c9373..5967e28d 100644 --- a/test/autogen.t/copy_array.smu +++ b/test/autogen.t/copy_array.smu @@ -1,3 +1,3 @@ -let a : array(u8) = [] +let a : array[u8] = [] let b& = copy(a) array/push(&b, !'2') diff --git a/test/autogen.t/rc.smu b/test/autogen.t/rc.smu index c4169883..451a5d94 100644 --- a/test/autogen.t/rc.smu +++ b/test/autogen.t/rc.smu @@ -4,7 +4,7 @@ let _ = copy(thing) let variant = rc/create(!#some("string")) copy(variant).ignore() -type thing = { a : option(array(int)) } +type thing = { a : option[array[int]] } let record& = rc/create(!{a = #some([1])}) &rc/get(record) = { a = #none } diff --git a/test/autogen.t/records.smu b/test/autogen.t/records.smu index 946f66bd..4548558f 100644 --- a/test/autogen.t/records.smu +++ b/test/autogen.t/records.smu @@ -38,8 +38,8 @@ -- (print (fmt-str (copy "test ") 1)) -type t = {c : float, a : string, b : int, d : array(int)} -type cont('a) = {a : 'a} +type t = {c : float, a : string, b : int, d : array[int]} +type cont['a] = {a : 'a} let a = {a = {a = "lul", b = 10, c = 10.0, d = [10, 20, 30]}} diff --git a/test/functions.t/generic_fun_arg.smu b/test/functions.t/generic_fun_arg.smu index 77f0cc3a..e030820b 100644 --- a/test/functions.t/generic_fun_arg.smu +++ b/test/functions.t/generic_fun_arg.smu @@ -1,6 +1,6 @@ external printi : (int) -> unit -type t('a) = {x : 'a} +type t['a] = {x : 'a} -- This fn is generic fun apply(x : 'a, f : ('a) -> 'b): diff --git a/test/functions.t/indirect_closure.smu b/test/functions.t/indirect_closure.smu index 17a6b07a..f22cdea7 100644 --- a/test/functions.t/indirect_closure.smu +++ b/test/functions.t/indirect_closure.smu @@ -1,6 +1,6 @@ external printi : (int) -> unit -type t('a) = {x : 'a} +type t['a] = {x : 'a} fun apply(x, f, env): f(x, env) diff --git a/test/functions.t/nested_closure_allocs.smu b/test/functions.t/nested_closure_allocs.smu index 12e9c885..961aa9e2 100644 --- a/test/functions.t/nested_closure_allocs.smu +++ b/test/functions.t/nested_closure_allocs.smu @@ -1,6 +1,6 @@ type view = {start : int, len : int} -type success('a) = {rem : view, mtch : 'a} -type parse_result('a) = #ok(success('a)) | #err(view) +type success['a] = {rem : view, mtch : 'a} +type parse_result['a] = #ok(success['a]) | #err(view) fun char(c): fun (buf, view): diff --git a/test/misc.t/abi.smu b/test/misc.t/abi.smu index a2706d8a..9d60fc21 100644 --- a/test/misc.t/abi.smu +++ b/test/misc.t/abi.smu @@ -9,7 +9,7 @@ type mixed4 = {x : float, y : float, z : float, k : int} type trailv2 = {a : int, b : int, c : float, d : float} type f2s = {fx : f32, fy : f32} type f3s = {fx : f32, fy : f32, fz : f32} -type shader = {id : i32, locs : raw_ptr(i32)} +type shader = {id : i32, locs : raw_ptr[i32]} external subv2 : (v2) -> v2 external subi2 : (i2) -> i2 diff --git a/test/misc.t/assert.smu b/test/misc.t/assert.smu index 77a790c1..3f53d6dd 100644 --- a/test/misc.t/assert.smu +++ b/test/misc.t/assert.smu @@ -1,5 +1,5 @@ -external stdout : raw_ptr(u8) -external fflush : (raw_ptr(u8)) -> unit +external stdout : raw_ptr[u8] +external fflush : (raw_ptr[u8]) -> unit assert(true) diff --git a/test/misc.t/free_array.smu b/test/misc.t/free_array.smu index 8deef97b..3e3054d5 100644 --- a/test/misc.t/free_array.smu +++ b/test/misc.t/free_array.smu @@ -1,5 +1,5 @@ type foo = {x : int} -type container = {index : int, arr : array(int)} +type container = {index : int, arr : array[int]} let x = {x = 1} diff --git a/test/misc.t/global_let.smu b/test/misc.t/global_let.smu index af0401a4..df5a4e44 100644 --- a/test/misc.t/global_let.smu +++ b/test/misc.t/global_let.smu @@ -1,10 +1,10 @@ fun ret_none(): - let a : option(array(int)) = #none + let a : option[array[int]] = #none a let b = !match ret_none(): #some(a): a | #none: [1, 2] ignore(b) -type r('a) = {a : 'a} +type r['a] = {a : 'a} fun ret_rec(): {a = [10, 20, 30]} let c = do: let a = ret_rec() diff --git a/test/misc.t/partials.smu b/test/misc.t/partials.smu index 1993df6d..67c09152 100644 --- a/test/misc.t/partials.smu +++ b/test/misc.t/partials.smu @@ -1,4 +1,4 @@ -type f('a) = {a : 'a, b : 'a, c : 'a} +type f['a] = {a : 'a, b : 'a, c : 'a} fun inf(): let a = {a = [10], b = [10], c = [10]} @@ -10,7 +10,7 @@ fun inf(): ignore(inf()) -type t('a) = {a& : 'a, b : 'a} +type t['a] = {a& : 'a, b : 'a} fun set_moved(): let a& = {a = [10], b = [20]} ignore((a.a, 0)) diff --git a/test/misc.t/rc_ifs.smu b/test/misc.t/rc_ifs.smu index 2f1219a4..914cb4c6 100644 --- a/test/misc.t/rc_ifs.smu +++ b/test/misc.t/rc_ifs.smu @@ -1,8 +1,8 @@ fun test(b): - let ret : array(int) = [] + let ret : array[int] = [] fun rec inner(i): - let ai : array(int) = [] - let bi : array(int) = [] + let ai : array[int] = [] + let bi : array[int] = [] if i == b: ai else: if i == 30: bi diff --git a/test/misc.t/rc_linear_closed_return.smu b/test/misc.t/rc_linear_closed_return.smu index d23e8ded..605d841b 100644 --- a/test/misc.t/rc_linear_closed_return.smu +++ b/test/misc.t/rc_linear_closed_return.smu @@ -1,5 +1,5 @@ fun test(): - let ret : array(int) = [] + let ret : array[int] = [] fun inner(i): ignore(i) copy(ret) diff --git a/test/misc.t/simple_typealias.smu b/test/misc.t/simple_typealias.smu index 52a6b93f..a20b1b5f 100644 --- a/test/misc.t/simple_typealias.smu +++ b/test/misc.t/simple_typealias.smu @@ -1,3 +1,3 @@ -type foo = raw_ptr(u8) +type foo = raw_ptr[u8] external puts : (foo) -> unit 0 diff --git a/test/misc.t/take_partial_alloc.smu b/test/misc.t/take_partial_alloc.smu index 71c8f144..8847d373 100644 --- a/test/misc.t/take_partial_alloc.smu +++ b/test/misc.t/take_partial_alloc.smu @@ -1,6 +1,6 @@ type view = {buf : string, start : int, len : int} -type success('a) = {rem : view, mtch : 'a} -type parse_result('a) = #ok(success('a)) | #err(view) +type success['a] = {rem : view, mtch : 'a} +type parse_result['a] = #ok(success['a]) | #err(view) fun view_of_string(str): {buf = copy(str), start = 0, len = string/len(str)} diff --git a/test/misc.t/take_partial_alloc_reorder.smu b/test/misc.t/take_partial_alloc_reorder.smu index 9d7c8a7a..26850e1c 100644 --- a/test/misc.t/take_partial_alloc_reorder.smu +++ b/test/misc.t/take_partial_alloc_reorder.smu @@ -1,6 +1,6 @@ type view = {buf : string, start : int, len : int} -type success('a) = {rem : view, mtch : 'a} -type parse_result('a) = #ok(success('a)) | #err(view) +type success['a] = {rem : view, mtch : 'a} +type parse_result['a] = #ok(success['a]) | #err(view) fun view_of_string(str): {buf = copy(str), start = 0, len = string/len(str)} diff --git a/test/modules.t/import_poly_func.smu b/test/modules.t/import_poly_func.smu index 2b08c2e1..69fc3536 100644 --- a/test/modules.t/import_poly_func.smu +++ b/test/modules.t/import_poly_func.smu @@ -6,5 +6,5 @@ external printf : (string/cstr, int) -> unit classify(#some(3)) |> printf(string/data("%i\n")) classify(#some(3.0)) |> printf(string/data("%i\n")) -let none : option(float) = #none +let none : option[float] = #none classify(none) |> printf(string/data("%i\n")) diff --git a/test/modules.t/local_import_poly_func.smu b/test/modules.t/local_import_poly_func.smu index 7b4e2775..f02a41e8 100644 --- a/test/modules.t/local_import_poly_func.smu +++ b/test/modules.t/local_import_poly_func.smu @@ -4,5 +4,5 @@ external printf : (string/cstr, int) -> unit poly_func/classify(#some(3)) |> printf(string/data("%i\n")) poly_func/classify(#some(3.0)) |> printf(string/data("%i\n")) -let none : poly_func/option(float) = #none +let none : poly_func/option[float] = #none poly_func/(classify(none) |> printf(string/data("%i\n"))) diff --git a/test/modules.t/nested_fn.smu b/test/modules.t/nested_fn.smu index 4ba0e8b0..f71aa162 100644 --- a/test/modules.t/nested_fn.smu +++ b/test/modules.t/nested_fn.smu @@ -1,4 +1,4 @@ -type thing('a) = #empty | #item('a) +type thing['a] = #empty | #item('a) fun classify(thing): fun inner(thing): match thing: diff --git a/test/modules.t/nullvec.smu b/test/modules.t/nullvec.smu index 09399f82..8789370e 100644 --- a/test/modules.t/nullvec.smu +++ b/test/modules.t/nullvec.smu @@ -1,14 +1,14 @@ signature: - type t('a) + type t['a] - val create : () -> t('a) - val singleton : ('a!) -> t('a) - val length : (t('a)) -> int - val push : (t('a)&, 'a!) -> unit - val iter : (t('a), ('a) -> unit) -> unit + val create : () -> t['a] + val singleton : ('a!) -> t['a] + val length : (t['a]) -> int + val push : (t['a]&, 'a!) -> unit + val iter : (t['a], ('a) -> unit) -> unit -type t('a) = option(array('a)) +type t['a] = option[array['a]] fun create(): #none diff --git a/test/modules.t/poly_func.smu b/test/modules.t/poly_func.smu index d2deb10f..84ef8fdf 100644 --- a/test/modules.t/poly_func.smu +++ b/test/modules.t/poly_func.smu @@ -1,5 +1,5 @@ -- don't use option because it will show up in the smi and make diffs difficult -type option('a) = #some('a) | #none +type option['a] = #some('a) | #none fun classify(thing): match thing: diff --git a/test/modules.t/poly_lambda.smu b/test/modules.t/poly_lambda.smu index 8510233c..ec218803 100644 --- a/test/modules.t/poly_lambda.smu +++ b/test/modules.t/poly_lambda.smu @@ -1,4 +1,4 @@ -type t('a) = {a : 'a} +type t['a] = {a : 'a} fun create(a): -- Create a polymorphic lambda and use it in this function. diff --git a/test/modules.t/simple_functor.smu b/test/modules.t/simple_functor.smu index c4193056..bf3a2e3e 100644 --- a/test/modules.t/simple_functor.smu +++ b/test/modules.t/simple_functor.smu @@ -3,7 +3,7 @@ module type sig: val hash : (t) -> int functor make(m : sig): - type other('a) = {this : m/t, other : 'a} + type other['a] = {this : m/t, other : 'a} fun create(this!, other!): println(fmt("create: ", this, " ", other)) diff --git a/test/modules.t/use_nested_fn.smu b/test/modules.t/use_nested_fn.smu index ebcd59db..a3cbefe2 100644 --- a/test/modules.t/use_nested_fn.smu +++ b/test/modules.t/use_nested_fn.smu @@ -1,5 +1,5 @@ import nested_fn use nested_fn -let a : thing(int) = #empty +let a : thing[int] = #empty classify(a) diff --git a/test/mutable_value_semantics.t/array_in_record_copies.smu b/test/mutable_value_semantics.t/array_in_record_copies.smu index a1941a2e..ebbb60d3 100644 --- a/test/mutable_value_semantics.t/array_in_record_copies.smu +++ b/test/mutable_value_semantics.t/array_in_record_copies.smu @@ -1,4 +1,4 @@ -type arrec = {a& : array(int)} +type arrec = {a& : array[int]} let a& = {a = [10]} let b = copy(a) diff --git a/test/mutable_value_semantics.t/dyn_partial_move.smu b/test/mutable_value_semantics.t/dyn_partial_move.smu index 999a7914..fa2ccc2a 100644 --- a/test/mutable_value_semantics.t/dyn_partial_move.smu +++ b/test/mutable_value_semantics.t/dyn_partial_move.smu @@ -1,4 +1,4 @@ -type wrap('a) = { a : 'a } +type wrap['a] = { a : 'a } fun remove(optarr&, index): let opt& = &optarr.[index.a] diff --git a/test/mutable_value_semantics.t/member_refcounts.smu b/test/mutable_value_semantics.t/member_refcounts.smu index 66411135..c9185044 100644 --- a/test/mutable_value_semantics.t/member_refcounts.smu +++ b/test/mutable_value_semantics.t/member_refcounts.smu @@ -1,4 +1,4 @@ -type r = {a : array(int)} +type r = {a : array[int]} let a& = [10] let r = {a = copy(a)} &a.[0] = 20 diff --git a/test/mutable_value_semantics.t/partial_move_set.smu b/test/mutable_value_semantics.t/partial_move_set.smu index 19d551f1..f6a9c4db 100644 --- a/test/mutable_value_semantics.t/partial_move_set.smu +++ b/test/mutable_value_semantics.t/partial_move_set.smu @@ -1,4 +1,4 @@ -type rr = {a : array(int), b : array(int)} +type rr = {a : array[int], b : array[int]} let a& = {a = [], b = []} ignore((a.a, 0)) diff --git a/test/mutable_value_semantics.t/partially_move_parameter.smu b/test/mutable_value_semantics.t/partially_move_parameter.smu index 653d4c34..b970cfa3 100644 --- a/test/mutable_value_semantics.t/partially_move_parameter.smu +++ b/test/mutable_value_semantics.t/partially_move_parameter.smu @@ -1,4 +1,4 @@ -type rr = {a& : array(int), b : array(int)} +type rr = {a& : array[int], b : array[int]} fun test(p&): &p.a = [10] do: let a& = {a = [], b = []} diff --git a/test/records.t/free_missing_fields.smu b/test/records.t/free_missing_fields.smu index ed0f8757..bfde9cbb 100644 --- a/test/records.t/free_missing_fields.smu +++ b/test/records.t/free_missing_fields.smu @@ -1,4 +1,4 @@ -type record('a) = {int : int, thing : 'a} +type record['a] = {int : int, thing : 'a} do: let r = {int = 0, thing = ([0, 1, 2], 0)} match(#some(r)): diff --git a/test/records.t/misaligned_get.smu b/test/records.t/misaligned_get.smu index 38948577..bc6cc597 100644 --- a/test/records.t/misaligned_get.smu +++ b/test/records.t/misaligned_get.smu @@ -1,7 +1,7 @@ external printi : (int) -> unit type inner = {fst : int, snd : int} -type misaligned('a) = {fst : inner, gen : 'a} +type misaligned['a] = {fst : inner, gen : 'a} fun gen(any): copy(any.gen) diff --git a/test/records.t/missing_parameter.smu b/test/records.t/missing_parameter.smu index fc932b4a..38a97d14 100644 --- a/test/records.t/missing_parameter.smu +++ b/test/records.t/missing_parameter.smu @@ -1,5 +1,5 @@ -type t('a) = {t : 'a} +type t['a] = {t : 'a} -fun correct(t : t(int)): t.t +fun correct(t : t[int]): t.t fun (t : t): t.t diff --git a/test/records.t/nested.smu b/test/records.t/nested.smu index 51425d02..3f4d93d8 100644 --- a/test/records.t/nested.smu +++ b/test/records.t/nested.smu @@ -1,9 +1,9 @@ external printi : (int) -> unit -type innerst('b) = { a : 'b } -type p_inner('a) = { a : 'a } -type alias('a) = p_inner('a) -type t('a) = { x : int, inner : alias(innerst('a)) } +type innerst['b] = { a : 'b } +type p_inner['a] = { a : 'a } +type alias['a] = p_inner['a] +type t['a] = { x : int, inner : alias[innerst['a]] } type inner = { a : int } diff --git a/test/records.t/nested_prealloc.smu b/test/records.t/nested_prealloc.smu index fadfa7a7..e5556675 100644 --- a/test/records.t/nested_prealloc.smu +++ b/test/records.t/nested_prealloc.smu @@ -1,8 +1,8 @@ external printi : (int) -> unit type int_wrap = {dat : int, b : int, c : int} -type test('a) = {int_wrap : 'a} -type mut('a) = {wrapped& : 'a} +type test['a] = {int_wrap : 'a} +type mut['a] = {wrapped& : 'a} fun test_thing(): let test = {int_wrap = {dat = 2, b = 0, c = 0}} diff --git a/test/records.t/parametrized_get.smu b/test/records.t/parametrized_get.smu index 6dac71d0..5921a6bd 100644 --- a/test/records.t/parametrized_get.smu +++ b/test/records.t/parametrized_get.smu @@ -1,7 +1,7 @@ external printi : (int) -> unit -type t('a) = {null : int, first : int, gen : 'a, third : bool} -type gen_first('a) = {only : 'a, is : bool} +type t['a] = {null : int, first : int, gen : 'a, third : bool} +type gen_first['a] = {only : 'a, is : bool} fun print_bool(b): if b: printi(1) else: printi(0) diff --git a/test/records.t/parametrized_pass.smu b/test/records.t/parametrized_pass.smu index f631d344..fea60d47 100644 --- a/test/records.t/parametrized_pass.smu +++ b/test/records.t/parametrized_pass.smu @@ -1,6 +1,6 @@ external printi : (int) -> unit -type t('a) = {first : int, gen : 'a, third : bool} +type t['a] = {first : int, gen : 'a, third : bool} fun apply(f : ('b) -> 'a, x : 'b): f(x) diff --git a/test/typing.ml b/test/typing.ml index 44820757..314aa017 100644 --- a/test/typing.ml +++ b/test/typing.ml @@ -167,10 +167,10 @@ let test_record_nested_field_infer () = {x = 12, y = {x = 12}}" let test_record_nested_field_generic () = - test "c(b)" + test "c[b]" "type a = {x : int}\n\ type b = {x : int}\n\ - type c('a) = {x : int, y : 'a}\n\ + type c['a] = {x : int, y : 'a}\n\ {x = 12, y = {x = 12}}" let test_record_field_no_record () = @@ -190,12 +190,12 @@ let test_record_update () = "type a = {x : int, y : int}\nlet a = {x = 10, y = 20}\n{a with y = 30}" let test_record_update_poly_same () = - test "a(int)" - "type a('a) = {x : 'a, y : int}\nlet a = {x = 10, y = 20}\n{a with x = 20}" + test "a[int]" + "type a['a] = {x : 'a, y : int}\nlet a = {x = 10, y = 20}\n{a with x = 20}" let test_record_update_poly_change () = - test "a(float)" - "type a('a) = {x : 'a, y : int}\n\ + test "a[float]" + "type a['a] = {x : 'a, y : int}\n\ let a = {x = 10, y = 20}\n\ {a with x = 20.0}" @@ -210,7 +210,7 @@ let test_record_update_expr () = let test_record_update_wrong_field () = test_exn "Unbound field z on a" - "type a('a) = {x : 'a, y : int}\nlet a = {x = 10, y = 20}\n{a with z = 20}" + "type a['a] = {x : 'a, y : int}\nlet a = {x = 10, y = 20}\n{a with z = 20}" let test_record_update_unknown_polymorphic () = test "unit" @@ -221,7 +221,7 @@ ignore(update)|} let test_annot_concrete () = test "(int) -> bool" "fun foo(x): x < 3\nfoo" let test_annot_rc () = - test "(rc(array(int))) -> unit" "fun foo(x : rc(array(int))): ()\nfoo" + test "(rc[array[int]]) -> unit" "fun foo(x : rc[array[int]]): ()\nfoo" let test_annot_concrete_fail () = test_exn @@ -255,32 +255,32 @@ let test_annot_record_simple () = test "a" "type a = {x : int}\ntype b = {x : int}\nlet a : a = {x = 12}\na" let test_annot_record_generic () = - test "a(bool)" - "type a('a) = {x : 'a}\ntype b = {x : int}\nlet a : a(bool) = {x = true}\na" + test "a[bool]" + "type a['a] = {x : 'a}\ntype b = {x : int}\nlet a : a[bool] = {x = true}\na" let test_annot_record_generic_multiple () = test_exn "Type a expects 2 type parameters" - "type a('a, 'b) = {x : 'a, y : 'b}\nlet a : a = {x = true}\na" + "type a['a, 'b] = {x : 'a, y : 'b}\nlet a : a = {x = true}\na" let test_annot_tuple_simple () = test "(int, bool)" "let a : (int, bool) = (1, true)\na" let test_annot_array_arg_generic () = - test "array(int)" "fun foo(a! : array('a)): a\nfoo(![10])" + test "array[int]" "fun foo(a! : array['a]): a\nfoo(![10])" let test_annot_tuple_generic () = test "(int, bool)" "fun hmm(a! : (int, 'a)): a\nhmm(!(1, true))" let test_annot_fixed_size_array () = - test "array#32(int)" "fun hmm(a! : array#32('a)): a\nhmm(!#32[0])" + test "array#32[int]" "fun hmm(a! : array#32['a]): a\nhmm(!#32[0])" let test_annot_fixed_unknown_size_array () = - test "array#32(int)" "fun hmm(a! : array#?('a)): a\nhmm(!#32[0])" + test "array#32[int]" "fun hmm(a! : array#?['a]): a\nhmm(!#32[0])" let test_annot_fixed_unknown_size_array_fn () = (* The function is instantiated so the size is not generalized. That's why there are two question marks. *) - test "(array#??('a)!) -> array#??('a)" "fun hmm(a! : array#?('a)): a\nhmm" + test "(array#??['a]!) -> array#??['a]" "fun hmm(a! : array#?['a]): a\nhmm" let test_sequence () = test "int" "external printi : (int) -> unit\nprinti(20)\n1 + 1" @@ -292,24 +292,24 @@ let test_sequence_fail () = but found [int]" "fun add1(x): x + 1\nadd1(20)\n1 + 1" let test_para_instantiate () = - test "foo(int)" - "type foo('a) = {first : int, gen : 'a}\n\ + test "foo[int]" + "type foo['a] = {first : int, gen : 'a}\n\ let foo = {first = 10, gen = 20}\n\ foo" let test_para_gen_fun () = - test "(foo('a)) -> int" - "type foo('a) = {gen : 'a, second : int}\n\ + test "(foo['a]) -> int" + "type foo['a] = {gen : 'a, second : int}\n\ fun get(foo): copy(foo.second)\n\ get" let test_para_gen_return () = - test "(foo('a)!) -> 'a" - "type foo('a) = {gen : 'a}\nfun get(foo!): foo.gen\nget" + test "(foo['a]!) -> 'a" + "type foo['a] = {gen : 'a}\nfun get(foo!): foo.gen\nget" let test_para_multiple () = test "bool" - "type foo('a) = {gen : 'a}\n\ + "type foo['a] = {gen : 'a}\n\ fun get(foo): copy(foo.gen)\n\ let a = {gen = 12}\n\ let b : int = get(a)\n\ @@ -317,15 +317,15 @@ let test_para_multiple () = get(c)" let test_para_instance_func () = - test "(foo(int)) -> int" - "type foo('a) = {gen : 'a}\n\ + test "(foo[int]) -> int" + "type foo['a] = {gen : 'a}\n\ fun apply(foo): foo.gen + 17\n\ let foo = {gen = 17}\n\ apply" let test_para_instance_wrong_func () = test_exn "In record expression expecting [int] but found [bool]" - "type foo('a) = {gen : 'a}\n\ + "type foo['a] = {gen : 'a}\n\ fun apply(foo): foo.gen + 17\n\ let foo = {gen = 17}\n\ apply({gen = true})" @@ -364,41 +364,41 @@ let test_alias_simple () = test "(int) -> unit" "type foo = int\nexternal f : (foo) -> unit\nf" let test_alias_param_concrete () = - test "(raw_ptr(u8)) -> unit" - "type foo = raw_ptr(u8)\nexternal f : (foo) -> unit\nf" + test "(raw_ptr[u8]) -> unit" + "type foo = raw_ptr[u8]\nexternal f : (foo) -> unit\nf" let test_alias_param_quant () = - test "(raw_ptr('a)) -> unit" - "type foo('a) = raw_ptr('a)\nexternal f : (foo('a)) -> unit\nf" + test "(raw_ptr['a]) -> unit" + "type foo['a] = raw_ptr['a]\nexternal f : (foo['a]) -> unit\nf" let test_alias_param_missing () = test_exn "Type raw_ptr expects 1 type parameter" - "type foo('a) = raw_ptr('a)\nexternal f : (foo) -> unit\nf" + "type foo['a] = raw_ptr['a]\nexternal f : (foo) -> unit\nf" let test_alias_of_alias () = test "(int) -> int" "type foo = int\ntype bar = foo\nexternal f : (bar) -> foo\nf" let test_alias_labels () = - test "inner/t(int)" + test "inner/t[int]" {|module inner: - type t('a) = {a : 'a, b : int} -type t('a) = inner/t('a) + type t['a] = {a : 'a, b : int} +type t['a] = inner/t['a] {a = 20, b = 10} |} let test_alias_ctors () = - test "inner/t(int)" + test "inner/t[int]" {|module inner: - type t('a) = #noo | #yes('a) -type t('a) = inner/t('a) + type t['a] = #noo | #yes('a) +type t['a] = inner/t['a] #yes(10)|} let test_alias_ctors_dont_overwrite () = - test "(option(item('a))) -> option('a)" - {|type option('a) = #some('a) | #none -type item('a) = {value : 'a} -type slot('a) = option(item('a)) + test "(option[item['a]]) -> option['a]" + {|type option['a] = #some('a) | #none +type item['a] = {value : 'a} +type slot['a] = option[item['a]] fun get_item(slot): match slot: @@ -406,15 +406,15 @@ fun get_item(slot): #none: #none get_item|} -let test_array_lit () = test "array(int)" "[0, 1]" -let test_array_lit_trailing () = test "array(int)" "[0, 1,]" +let test_array_lit () = test "array[int]" "[0, 1]" +let test_array_lit_trailing () = test "array[int]" "[0, 1,]" -let test_array_var () = test "array(int)" {|let a = [0, 1] +let test_array_var () = test "array[int]" {|let a = [0, 1] a|} let test_array_weak () = - test "array(int)" - {|external setf : (array('a), 'a) -> unit + test "array[int]" + {|external setf : (array['a], 'a) -> unit let a = [] setf(a, 2) a|} @@ -423,18 +423,18 @@ let test_array_different_types () = test_exn "In array literal expecting [int] but found [bool]" "[0, true]" let test_array_different_annot () = - test_exn "In let binding expecting [array(int)] but found [array(bool)]" - "let a : array(bool) = [0, 1]\na" + test_exn "In let binding expecting [array[int]] but found [array[bool]]" + "let a : array[bool] = [0, 1]\na" let test_array_different_annot_weak () = test_exn "In application expecting (_, [bool]) -> _ but found (_, [int]) -> _" - "external setf : (array('a), 'a) -> unit\n\ - let a : array(bool) = []\n\ + "external setf : (array['a], 'a) -> unit\n\ + let a : array[bool] = []\n\ setf(a, 2)" let test_array_different_weak () = test_exn "In application expecting (_, [int]) -> _ but found (_, [bool]) -> _" - {|external setf : (array('a), 'a) -> unit + {|external setf : (array['a], 'a) -> unit let a = [] setf(a, 2) setf(a, true)|} @@ -467,7 +467,7 @@ let test_mutable_nonmut_transitive_inv () = let test_mutable_track_ptr_nonmut () = test_exn "Cannot project immutable binding" - "type thing = { ptr : raw_ptr(u8) }\n\ + "type thing = { ptr : raw_ptr[u8] }\n\ do:\n\ \ let thing = { ptr = __unsafe_nullptr() }\n\ \ let proj& = &(__unsafe_ptr_get(thing.ptr, 0))\n\ @@ -475,43 +475,43 @@ let test_mutable_track_ptr_nonmut () = let test_mutable_track_ptr_mut () = test "int" - "type thing = { ptr& : raw_ptr(u8) }\n\ + "type thing = { ptr& : raw_ptr[u8] }\n\ do:\n\ \ let thing& = { ptr = __unsafe_nullptr() }\n\ \ let proj& = &(__unsafe_ptr_get(thing.ptr, 0))\n\ \ 0" let test_variants_option_none () = - test_exn "Expression contains weak type variables: option('a)" - "type option('a) = #none | #some('a)\n#none" + test_exn "Expression contains weak type variables: option['a]" + "type option['a] = #none | #some('a)\n#none" let test_variants_option_some () = - test "option(int)" "type option('a) = #none | #some('a)\n#some(1)" + test "option[int]" "type option['a] = #none | #some('a)\n#some(1)" let test_variants_option_some_some () = - test "option(option(float))" - "type option('a) = #none | #some('a)\nlet a = #some(1.0)\n#some(copy(a))" + test "option[option[float]]" + "type option['a] = #none | #some('a)\nlet a = #some(1.0)\n#some(copy(a))" let test_variants_option_annot () = - test "option(option(float))" - "type option('a) = #none | #some('a)\n\ - let a : option(float) = #none\n\ + test "option[option[float]]" + "type option['a] = #none | #some('a)\n\ + let a : option[float] = #none\n\ #some(a)" let test_variants_option_none_arg () = test_exn "The constructor none expects 0 arguments, but an argument is provided" - "type option('a) = #none | #some('a)\n#none(1)" + "type option['a] = #none | #some('a)\n#none(1)" let test_variants_option_some_arg () = test_exn "The constructor some expects arguments, but none are provided" - "type option('a) = #none | #some('a)\n#some" + "type option['a] = #none | #some('a)\n#some" let test_variants_correct_inference () = test "unit" {|type view = {start : int, len : int} -type success('a) = {rem : view, mtch : int} -type parse_result('a) = #ok(success('a)) | #err(view) +type success['a] = {rem : view, mtch : int} +type parse_result['a] = #ok(success['a]) | #err(view) fun map(p, f, buf, view): match p(buf, view): #ok(ok): #ok({ok with mtch = f(ok.mtch)}) @@ -526,21 +526,21 @@ let test_lor_other_variant () = let test_match_all () = test "int" - "type option('a) = #none | #some('a)\n\ + "type option['a] = #none | #some('a)\n\ match #some(1): #some(a): a | #none: -1" let test_match_redundant () = test_exn "Pattern match case is redundant" - "type option('a) = #none | #some('a)\nmatch #some(1): a: a | #none: -1" + "type option['a] = #none | #some('a)\nmatch #some(1): a: a | #none: -1" let test_match_missing () = test_exn "Pattern match is not exhaustive. Missing cases: #some" - "type option('a) = #none | #some('a)\nmatch #some(1): #none: -1" + "type option['a] = #none | #some('a)\nmatch #some(1): #none: -1" let test_match_missing_nested () = test_exn "Pattern match is not exhaustive. Missing cases: #some(#int) | #some(#non)" - {|type option('a) = #none | #some('a) + {|type option['a] = #none | #some('a) type test = #float(float) | #int(int) | #non match #none: #some(#float(f)): f.int_of_float() @@ -551,17 +551,17 @@ match #none: let test_match_all_after_ctor () = test "int" - {|type option('a) = #none | #some('a) + {|type option['a] = #none | #some('a) match #some(1): #none: -1 | a: 0|} let test_match_all_before_ctor () = test_exn "Pattern match case is redundant" - {|type option('a) = #none | #some('a) + {|type option['a] = #none | #some('a) match #some(1): a: 0 | #none: -1|} let test_match_redundant_all_cases () = test_exn "Pattern match case is redundant" - {|type option('a) = #none | #some('a) + {|type option['a] = #none | #some('a) type test = #float(float) | #int(int) | #non match #none: #some(#float(f)): f.int_of_float() @@ -573,12 +573,12 @@ match #none: let test_match_wildcard () = test_exn "Pattern match case is redundant" - {|type option('a) = #none | #some('a) + {|type option['a] = #none | #some('a) match #some(1): _: 0 | #none: -1|} let test_match_wildcard_nested () = test_exn "Pattern match case is redundant" - {|type option('a) = #none | #some('a) + {|type option['a] = #none | #some('a) type test = #float(float) | #int(int) | #non match #none: #some(#float(f)): f.int_of_float() @@ -592,14 +592,14 @@ let test_match_column_arity () = "Tuple pattern has unexpected type:\n\ expecting [(int, int)]\n\ but found [(int, int, 'a)]" - {|type option('a) = #none | #some('a) + {|type option['a] = #none | #some('a) match (1, 2): (a, b, c): a |} let test_match_record () = test "int" - {|type option('a) = #none | #some('a) + {|type option['a] = #none | #some('a) type foo = {a : int, b : float} match #some({a = 12, b = 53.0}): #some({a, b}): a @@ -608,7 +608,7 @@ match #some({a = 12, b = 53.0}): let test_match_record_field_missing () = test_exn "There are missing fields in record pattern, for instance b" - {|type option('a) = #none | #some('a) + {|type option['a] = #none | #some('a) type foo = {a : int, b : float} match #some({a = 12, b = 53.0}): #some({a}): a @@ -617,7 +617,7 @@ match #some({a = 12, b = 53.0}): let test_match_record_field_twice () = test_exn "Field a appears multiple times in record pattern" - {|type option('a) = #none | #some('a) + {|type option['a] = #none | #some('a) type foo = {a : int, b : float} match #some({a = 12, b = 53.0}): #some({a, a}): a @@ -626,7 +626,7 @@ match #some({a = 12, b = 53.0}): let test_match_record_field_wrong () = test_exn "Unbound field c on record foo" - {|type option('a) = #none | #some('a) + {|type option['a] = #none | #some('a) type foo = {a : int, b : float} match #some({a = 12, b = 53.0}): #some({a, c}): a @@ -636,34 +636,34 @@ match #some({a = 12, b = 53.0}): let test_match_record_case_missing () = test_exn "Pattern match is not exhaustive. Missing cases: #some(#none)" {| -type option('a) = #none | #some('a) -type foo('a) = {a : 'a, b : float} +type option['a] = #none | #some('a) +type foo['a] = {a : 'a, b : float} match #some({a = #some(2), b = 53.0}): #some({a = #some(a), b}): a #none: 0|} let test_match_int () = test "int" - {|type option('a) = #none | #some('a) + {|type option['a] = #none | #some('a) match #some(10): #some(1): 1 | #some(10): 10 | #some(_): 0 | #none: -1 |} let test_match_int_wildcard_missing () = test_exn "Pattern match is not exhaustive. Missing cases: " - {|type option('a) = #none | #some('a) + {|type option['a] = #none | #some('a) match #some(10): #some(1): 1 | #some(10): 10 | #none: -1|} let test_match_int_twice () = test_exn "Pattern match case is redundant" {| -type option('a) = #none | #some('a) +type option['a] = #none | #some('a) match #some(10): #some(1): 1 | #some(10): 10 | #some(10): 10 | #some(_): 0 | #none: -1 |} let test_match_int_after_catchall () = test_exn "Pattern match case is redundant" {| -type option('a) = #none | #some('a) +type option['a] = #none | #some('a) match #some(10): #some(1): 1 | #some(_): 10 | #some(10): 10 | #none: -1 |} @@ -677,12 +677,12 @@ let test_match_or_redundant () = "match (1, 2): (a, 1) | (a, 2) | (a, 1): a | _: -1" let test_multi_record2 () = - test "foo(int, bool)" - "type foo('a, 'b) = {a : 'a, b : 'b}\n{a = 0, b = false}" + test "foo[int, bool]" + "type foo['a, 'b] = {a : 'a, b : 'b}\n{a = 0, b = false}" let test_multi_variant2 () = - test_exn "Expression contains weak type variables: foo(int, 'a)" - "type foo('a, 'b) = #some('a) | #other('b)\n#some(1)" + test_exn "Expression contains weak type variables: foo[int, 'a]" + "type foo['a, 'b] = #some('a) | #other('b)\n#some(1)" let test_tuple () = test "(int, float)" "( 1, 2.0 )" let test_pattern_decl_var () = test "int" "let a = 123\na" @@ -728,11 +728,11 @@ type t = float|} let test_signature_generic () = test "unit" {|signature: - type t('a) - val create : ('a!) -> t('a) - val create_int : (int) -> t(int) + type t['a] + val create : ('a!) -> t['a] + val create_int : (int) -> t[int] -type t('a) = {x : 'a} +type t['a] = {x : 'a} fun create(x!): {x} fun create_int(x : int): {x}|} @@ -740,18 +740,18 @@ fun create_int(x : int): {x}|} let test_signature_param_mismatch () = test_exn "Signatures don't match for value create_int:\n\ - expecting (_) -> [t(int)]\n\ - but found (_) -> [t('a)]" + expecting (_) -> [t[int]]\n\ + but found (_) -> [t['a]]" {|signature: - type t('a) - val create_int : (int) -> t(int) -type t('a) = {x : int} + type t['a] + val create_int : (int) -> t[int] +type t['a] = {x : int} fun create_int(x : int): {x}|} let test_signature_unparam_type () = test "unit" {|signature: - type t('a) -type t('a) = int|} + type t['a] +type t['a] = int|} let test_signature_abstract () = test "unit" @@ -759,7 +759,7 @@ let test_signature_abstract () = type t val len : (t) -> int -type t = array(u8) +type t = array[u8] fun len(str : t): __unsafe_array_length(str) |} @@ -945,7 +945,7 @@ fun ease(anim): match anim: let test_excl_shadowing () = test_exn "Borrowed parameter a is moved" "fun thing(a):\n let a = a\n a" -let typ = "type string = array(u8)\ntype t = {a : string, b : string}\n" +let typ = "type string = array[u8]\ntype t = {a : string, b : string}\n" let test_excl_parts_success () = test "unit" (typ ^ "fun meh(a!): {a = a.a, b = a.b}") @@ -977,15 +977,15 @@ let test_excl_fn_not_copy_capture () = let test_excl_partial_move_reset () = test_exn "Cannot move top level binding" - {|type tt = {a& : array(int), b & : array(int)} + {|type tt = {a& : array[int], b & : array[int]} let a& = {a = [], b = []} let _ = !a.a let _ = !a.b &a.b = []|} let test_excl_projections_partial_moves () = - test "array(int)" - {|type t = {a& : array(int), b& : array(int)} + test "array[int]" + {|type t = {a& : array[int], b& : array[int]} let a& = {a = [], b = []} do: let a& = &a @@ -1030,7 +1030,7 @@ do: let test_excl_track_rc_get () = test_exn "state was mutably borrowed in line 10, cannot borrow" - {|type state('a, 'b) = { fst& : 'a, snd : 'b } + {|type state['a, 'b] = { fst& : 'a, snd : 'b } fun higher_lvl(thing&, f): () @@ -1260,16 +1260,16 @@ let check_sig_test thing = module type sig: type key - type t('value) + type t['value] - val create : (int) -> t(|} + val create : (int) -> t[|} ^ thing - ^ {|) + ^ {|] functor make : sig (m : key): type key = m/t - type item('a) = {key : m/t, value : 'a} - type slot('a) = #empty | #tombstone | #item(item('a)) - type t('a) = {data& : array(slot('a)), nitems& : int} + type item['a] = {key : m/t, value : 'a} + type slot['a] = #empty | #tombstone | #item(item['a]) + type t['a] = {data& : array[slot['a]], nitems& : int} fun create(size : int): ignore(size) @@ -1281,14 +1281,14 @@ let test_functor_check_sig () = test "unit" (check_sig_test "'value") let test_functor_check_param () = test_exn "Signatures don't match for value create:\n\ - expecting (_) -> [t(key)]\n\ - but found (_) -> [t('a)]" (check_sig_test "key") + expecting (_) -> [t[key]]\n\ + but found (_) -> [t['a]]" (check_sig_test "key") let test_functor_check_concrete () = test_exn "Signatures don't match for value create:\n\ - expecting (_) -> [t(int)]\n\ - but found (_) -> [t('a)]" (check_sig_test "int") + expecting (_) -> [t[int]]\n\ + but found (_) -> [t['a]]" (check_sig_test "int") let test_functor_sgn_only_type () = test "unit" @@ -1355,32 +1355,32 @@ let test_syntax_let_block_other_equal () = "type record = {a : int}\nlet {a =\n b} =\n let b = 0\n {a = 10}" let test_rec_type_pos () = - test "unit" "type list('a) = #nil | #cons('a, rc(list))" + test "unit" "type list['a] = #nil | #cons('a, rc[list])" let test_rec_type_pos_array () = - test "unit" "type list('a) = #nil | #cons('a, array(list))" + test "unit" "type list['a] = #nil | #cons('a, array[list])" let test_rec_type_noptr () = - test_exn "Infinite type" "type list('a) = #cons('a, list)" + test_exn "Infinite type" "type list['a] = #cons('a, list)" let test_rec_type_noptr_array () = - test_exn "Infinite type" "type list('a) = #cons('a, array#1(list))" + test_exn "Infinite type" "type list['a] = #cons('a, array#1[list])" let test_rec_type_nobase () = test_exn "Recursive type has no base case" - "type list('a) = #cons('a, rc(list))" + "type list['a] = #cons('a, rc[list])" let test_rec_type_record_param () = test "unit" - {|type container('a) = { a : 'a } -type state = { data : container((state&) -> unit)} + {|type container['a] = { a : 'a } +type state = { data : container[(state&) -> unit]} let _ = { data = {a = fun(state&): ignore(state)} }|} let test_rec_type_record_param_nobase () = test_exn "Recursive type has no base case" - {|type container('a) = { a : 'a } -type data('a) = { cb : 'a } -type state = { data : container(data(rc(state))) }|} + {|type container['a] = { a : 'a } +type data['a] = { cb : 'a } +type state = { data : container[data[rc[state]]] }|} let test_rec_type_record_fnreturn () = test "unit" "type t = { works : () -> t }" @@ -1389,24 +1389,24 @@ let test_rec_type_record_fnboth () = test "unit" "type t = { works : (t) -> t }" let test_rec_type_record_some_nobase () = test_exn "Recursive type has no base case" - "type t = { works : () -> t, doesnt : rc(t)}" + "type t = { works : () -> t, doesnt : rc[t]}" let test_rec_type_record_variant_base () = test "unit" - {|type option('a) = #none | #some('a) -type t = { a : rc(option(t)) }|} + {|type option['a] = #none | #some('a) +type t = { a : rc[option[t]] }|} let test_rec_type_record_wrap () = test "unit" - {|type option('a) = #none | #some('a) -type wrap('a) = { a : option('a) } -type t = { a : rc(wrap(t)) }|} + {|type option['a] = #none | #some('a) +type wrap['a] = { a : option['a] } +type t = { a : rc[wrap[t]] }|} let test_rec_type_record_wrap_twice () = test "unit" - {|type option('a) = #none | #some('a) -type wrap('a) = { a : option('a) } -type t = { a : rc(wrap(wrap(t))) }|} + {|type option['a] = #none | #some('a) +type wrap['a] = { a : option['a] } +type t = { a : rc[wrap[wrap[t]]] }|} let case str test = test_case str `Quick test @@ -1760,7 +1760,7 @@ let c = do: ignore((c, 0))|}; tase_exn "move binds individual" (ln "thing.value was moved in line %i, cannot use" 6) - {|type data = {key : array(u8), value : array(u8)} + {|type data = {key : array[u8], value : array[u8]} type data_container = #empty | #item(data) fun hmm(thing&): match thing: #item({key, value}): @@ -1769,7 +1769,7 @@ fun hmm(thing&): match thing: ignore((value, 0)) #empty: ()|}; tase_exn "move binds param" "Borrowed parameter thing is moved" - {|type data = {key : array(u8), value : array(u8)} + {|type data = {key : array[u8], value : array[u8]} type data_container = #empty | #item(data) fun hmm(thing&): match thing: #item({key, value}): @@ -1778,7 +1778,7 @@ fun hmm(thing&): match thing: #empty: ()|}; tase_exn "let pattern name" (ln "key was moved in line %i, cannot use" 4) - {|type data = {key : array(u8), value : array(u8)} + {|type data = {key : array[u8], value : array[u8]} fun hmm(): let {key, value} = !{key = ['k', 'e', 'y'], value = ['v', 'a', 'l', 'u', 'e']} ignore((key, 0)) @@ -1794,7 +1794,7 @@ fun hmm(): tase_exn "always borrow field" (ln "sm.free_hd was borrowed in line %i, cannot mutate" 7) {|type key = {idx : int, gen : int} -type t = {slots& : array(key), data& : array(int), free_hd& : int, erase& : array(int)} +type t = {slots& : array[key], data& : array[int], free_hd& : int, erase& : array[int]} do: let sm& = {slots = [], data = [], free_hd = -1, erase = []} diff --git a/test/variants.t/match_option.smu b/test/variants.t/match_option.smu index 2645bd7d..b3697bc0 100644 --- a/test/variants.t/match_option.smu +++ b/test/variants.t/match_option.smu @@ -27,5 +27,5 @@ some_all(#none) |> printf(cstr("%i\n")) fun none_all(p): match p: #none: 0 | _: 1 none_all(#some(1)) |> printf(cstr("%i\n")) -let none_int : option(int) = #none +let none_int : option[int] = #none none_all(none_int) |> printf(cstr("%i\n")) diff --git a/test/variants.t/match_record.smu b/test/variants.t/match_record.smu index 98b9458a..2d1070c7 100644 --- a/test/variants.t/match_record.smu +++ b/test/variants.t/match_record.smu @@ -1,4 +1,4 @@ -type foo('a) = {a : 'a, b : float} +type foo['a] = {a : 'a, b : float} fun test_record_in_variant(inner): let a = match(#some({a = inner, b = 53.0})): diff --git a/test/variants.t/recursive.smu b/test/variants.t/recursive.smu index aa11e780..65b2ad3c 100644 --- a/test/variants.t/recursive.smu +++ b/test/variants.t/recursive.smu @@ -1,18 +1,18 @@ -type list0('a) = #nil | #cons('a, rc(list0)) +type list0['a] = #nil | #cons('a, rc[list0]) let list = #cons(0, rc/create(!#cons(1, rc/create(!#cons(1, rc/create(!#cons(1, rc/create(!#cons(1, rc/create(!#nil)))))))))) let _ = copy(list) -type list('a) = #nil | #cons('a, option(rc(list))) +type list['a] = #nil | #cons('a, option[rc[list]]) let _ = rc/create(!#cons(1, #none)) let fst = rc/create(!#cons(1, #some(rc/create(!#nil)))) let _ = #cons(0, #some(fst.copy())) -- recursive record -type container('a) = { a : 'a } -type state = { data : container((state&) -> unit)} +type container['a] = { a : 'a } +type state = { data : container[(state&) -> unit]} -- this stack overflowed let _ = { data = {a = fun(state&): ignore(state)} } diff --git a/test/variants.t/tuple_match.smu b/test/variants.t/tuple_match.smu index 83dded50..61e1877d 100644 --- a/test/variants.t/tuple_match.smu +++ b/test/variants.t/tuple_match.smu @@ -8,7 +8,7 @@ fun doo(a, b): (_, #none): 0 |> printf(string/data("%i\n")) -let none_int : option(int) = #none +let none_int : option[int] = #none doo(#some(1), #some(2)) doo(none_int, #some(2))