1. 7
  1.  

  2. 2

    Is there a difference between a scale program where everything is explicitly typed then removing all of the types? For example, I cannot think of an example in Ocaml where, if I wrote a program explicitly typing everything and it compiled then removed the explicit types it would not continue to compile and function the same way as before.

    As for the article, I think this is one huge benefit of signatures in Ocaml. The first thing I do in my Ocaml programs is to define the .mli for a module, hide whateve types and give clear APIs, then implement it. Inside the module I don’t provide explicit types for anything, unless I’m debugging a compiler error, but the interface gives me a firewall of protection. I know, in a program, that I just nee to make the implementation of the interface internally consistent. The interface file is a meeting point where modules shake hands and agree with the types of values they will use.

    1. 2

      Is there a difference between a scale[sic] program where everything is explicitly typed then removing all of the types? For example, I cannot think of an example in Ocaml where, if I wrote a program explicitly typing everything and it compiled then removed the explicit types it would not continue to compile and function the same way as before.

      Yes - implicit resolution works based on type. So if for some reason you e.g. stored names as encoding + bytes rather than database strings (perhaps you have Han unification issues) you could define a custom database deserializer for Name, and get[Name] will use the custom deserializer while get[Address] uses the (automatically derived) standard String deserializer.

      (Also type inference in scala is not perfect because of subtyping so there are cases where code will fail to compile if the types are removed, but that’s almost an implementation detail)

      1. 1

        Won’t implicits get resolved during compilation? This is how Haskell typeclasses work.

        1. 2

          Yes, they’re resolved during compilation, by type. So you can write something like Monoid[Int].zero or Monoid[String].zero, and you’ll get different values from them - I assume this is the same for Haskell typeclasses? So you can’t just delete all types from a program and expect it to behave the same the way you can in OCaml.

          1. 2

            Oh, apologies, I misread the first question. I thought he meant type erasure during compilation.