I don’t doubt that I have a few more type checking errors in store for me
in the current version of list_min below (which ideally I would implement
in a more polymorphic manner). Right now I’m not sure about this error
about operator overloading (code highlighted in yellow).
This more simple case works fine, so I haven’t captured the essence of the
problem:
var a: double = 1.00
var b: double = 2.79
val x = if a < b then 1 else 0
error(3): the symbol [<] cannot be resolved: there are too many matches:
lt_string_string, lt_ssize1_int1, …
exit(ATS): uncaught exception:
_2fhome_2ffac2_2fhwxi_2fresearch_2fATS_2fIMPLEMENT_2fGeizella_2fAnairiats_2fsvn_2fats_2dlang_2fsrc_2fats_error_2esats__FatalErrorException(1233)
fn find (
SDmap: &map (string, double), k: string, res: &double?
) : void = () where {
val b = linmap_search (SDmap, k, lam(x,y) => compare_string_string(x,y),
res)
val () = if b then let
prval () = opt_unsome {double} (res)
in
print “Some(”; print res; print ")“
end else let
prval () = opt_unnone {double} (res) in ($raise InvalidCase; print
"None()”)
end // end of [val]
val () = print_newline ()
} // end of [find]
fun list_min (inlist: List string, emap: &map(string,double)): Option_vt
string = let
fun loop(cmin: string, rlist: List string, emap: &map(string,double)):
string = case+ rlist of
| list_cons (x, xs) => let
var xval: double
val _ = find(emap, x, xval)
var cminval: double
val _ = find(emap, cmin, cminval)
in
if cminval < xval then loop(cmin,xs,emap) else loop(x,xs,emap)
end
| list_nil () => cmin
in case+ inlist of
| list_cons (x, xs) => Some_vt(loop(x,xs))
| list_nil () => None_vt ()
end // end of [list_min]