Programming languages enthusiast. Author of Learn Type Driven Development: https://www.packtpub.com/application-development/learn-type-driven-development
Nope, printf is done with special macro system OCaml has just for format strings
Format strings are part of the equation, yes, but as the comment you pointed to notes, the printf functionality is defined in normal functions in the Printf/Scanf/Format modules. Format strings are just a syntax sugar; it's possible to desugar them to (something like) printf [Text "Hello, "; Format_s; Text "!\n"] name which would do the same job, just a little more verbosely.
This isn't required by any theoretical reason, Haskell deals with this perfectly fine, and even SML had some limited type classes IIRC.
Well, Haskell and OCaml explicitly are in very different design spaces here, and both have valid reasons for doing what they do. OCaml's more explicit style makes compilation faster and error messages simpler, for example. And SML doesn't have type classes, unless you're talking about the built-in non-extensible equality types.
I double checked it with OCaml source code, and it's full of ;;s
Yes, very old code still uses ;; but that has not been the convention for a long time now. For example, if you check the link you gave above, very little of that file is using ;;. And if you use ocamlformat, the standard code formatter, it will idiomatically remove ;;.
And tbh I'm not sure starting a lot of subsequent lines with let () = as it also sometimes does is really an improvement
Yes, we actually don't need to do that either. We can use ; which is the sequencing operator to do it pretty cleanly:
Format strings are part of the equation, yes, but as the comment you pointed to notes, the printf functionality is defined in normal functions in the
Printf
/Scanf
/Format
modules. Format strings are just a syntax sugar; it's possible to desugar them to (something like)printf [Text "Hello, "; Format_s; Text "!\n"] name
which would do the same job, just a little more verbosely.Well, Haskell and OCaml explicitly are in very different design spaces here, and both have valid reasons for doing what they do. OCaml's more explicit style makes compilation faster and error messages simpler, for example. And SML doesn't have type classes, unless you're talking about the built-in non-extensible equality types.
Yes, very old code still uses
;;
but that has not been the convention for a long time now. For example, if you check the link you gave above, very little of that file is using;;
. And if you useocamlformat
, the standard code formatter, it will idiomatically remove;;
.Yes, we actually don't need to do that either. We can use
;
which is the sequencing operator to do it pretty cleanly: