News for hackers. Stuff that matters.
Re:Is Go Duck-Typed? by int_19h on Thursday March 05, 2020 @04:35AM (#22492198)
OCaml has structural typing with full type inference:

   # let f obj = obj#foo 1 2;;
   val f : < foo : int -> int -> 'a; .. > -> 'a = <fun>
but it's generally not called duck typing.

I think the more dynamic nature is really the crucial difference. In OCaml, if the function above had an if/else, and called #foo in one branch, and #bar in the other, the type of the object would be inferred as having both methods, and would enforce that at compile time. With duck typing, you could pass something that only has #foo, so long as the right branch is taken.

There are no comments on this comment yet.