Languages With Some Form of Implicit Subtyping

Hello all. Caveat: I would have just searched on google et al, but I am not sure that I have the terminology correct. I think that I am looking for implicit structural subtyping. Essentially, I am looking for a language that would allow something like this:

fun f o = o.ToString()
fun g o = o.ToInt()

fun test o1 o2 =
let s1 = o1.ToString() in
let s2 = o2.ToString() in
let s = s1 ^ ", " ^ s2 in

let l = [s1, s2] in
let l' = map g l in
l'

Note that this should be statically typechecked. Essentially, I am looking for something with a type system similar to O'Caml's object system with row variables, but allowing for the line [s1, s2] without use of the operator :> (or whatever it is) to explicitly state some subtype relationship. That is, l' would have the type of a list of objects implementing ToInt(), where ToInt() has type () -> '_a, that is, ToInt() takes unit and returns some type not yet determined, but that will be. A key aspect that I am looking for is broad use of inference so that one doesn't have to explicitly annotate subtyping relationships, at least not often. If you can think of languages with similar type systems, I would appreciate it. If you could note the differences or constraints as well, that would be great!

Just a note, I am not looking for a language to use, nor one with precisely the above semantics and syntax. I am mostly just interested in the theory behind such kinds of type checking. I hope that I got the name right, but pointers to other keywords to search on would help, too.

Thanks, sorry if this is not the right forum for such a post.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

You can do something with a

You can do something with a similar effect using type classes and existential types in Haskell. See for example Sec. 4.4 in this paper for a detailed explanation. By the way, the example used in that paper is quite similar (mapping a polymorphic function over a heterogenous list).