TypeChecker.fs

 avatar
unknown
plain_text
2 years ago
1.3 kB
3
Indexable
| Scan (f, e_exp, arr_exp, _, pos) ->
        let (e_type, e_dec) = checkExp ftab vtab e_exp
        let (arr_type, arr_dec) = checkExp ftab vtab arr_exp
        let elem_type = match arr_type with
                        | Array t -> t
                        | other -> raise (MyError ("Scan: Argument not an array", pos))
        let (f', f_arg_type) = match checkFunArg ftab vtab pos f with
                                | (f', res, [a1; a2]) ->
                                  if a1 = a2 && a2 = res
                                  then (f', res)
                                  else raise (MyError( "Scan: incompatible function type of " + (ppFunArg 0 f) + ": " + showFunType ([a1; a2], res), pos))
                                | (_, res, args) -> raise (MyError ( "Scan: incompatible function type of " + ppFunArg 0 f + ": " + showFunType (args, res), pos))
        let err (s, t) = MyError ( "Scan: unexpected " + s + " type " + ppType t + ", expected " + ppType f_arg_type, pos)
        if   elem_type = f_arg_type && elem_type = e_type then
              (Array elem_type, Scan (f', e_dec, arr_dec, elem_type, pos))
        elif elem_type = f_arg_type then
              raise (err ("neutral element", e_type))
        else raise (err ("array element", elem_type))
Editor is loading...