This commit is contained in:
NikolajDanger
2022-05-25 16:01:54 +02:00
parent 5f7c450809
commit 3cce70432d
6 changed files with 1048 additions and 754 deletions

View File

@ -325,16 +325,18 @@ and checkExp (ftab : FunTable)
let elem_type =
match arr_type with
| Array t -> t
| _ -> reportTypeWrongKind "second argument of map" "array" arr_type pos
| _ -> reportTypeWrongKind "second argument of filter" "array" arr_type pos
let (f', f_res_type, f_arg_type) =
match checkFunArg ftab vtab pos f with
| (f', res, [a1]) -> (f', res, a1)
| (_, res, args) ->
reportArityWrong "first argument of map" 1 (args,res) pos
reportArityWrong "first argument of filter" 1 (args,res) pos
if not (f_res_type = Bool) then
reportTypesDifferent "function return-type not bool in filter" f_res_type Bool pos
if elem_type <> f_arg_type then
reportTypesDifferent "function-argument and array-element types in map"
f_arg_type elem_type pos
(Array f_res_type, Map (f', arr_exp_dec, elem_type, f_res_type, pos))
reportTypesDifferent "function-argument and array-element types in filter" f_arg_type elem_type pos
(Array f_arg_type, Filter (f', arr_exp_dec, elem_type, pos))
(* TODO project task 2: `scan(f, ne, arr)`
Hint: Implementation is very similar to `reduce(f, ne, arr)`.
@ -367,7 +369,7 @@ and checkExp (ftab : FunTable)
if e_type <> f_argres_type then
reportTypesDifferent "operation and start-element types in scan"
f_argres_type e_type pos
(f_argres_type, Reduce (f', e_dec, arr_dec, elem_type, pos))
(Array f_argres_type, Scan (f', e_dec, arr_dec, elem_type, pos))
and checkFunArg (ftab : FunTable)
(vtab : VarTable)