|
|
|
|
|
by themulticaster
1868 days ago
|
|
> It has some nice things like automatic type inference so you don't have to write very many type annotations. I'm not quite sure what you're going for here. The Hindley-Milner type system Haskell is based on essentially does not require any type annotations [1]. By convention, every top-level declaration is annotated, but that is only for documentation and clarity. Or did you mean that in comparing OCaml and Haskell to other (imperative) languages? [1] There are a few buts that don't have much to do with the argument, but I'll list them here anyway: 1) Sometimes the type you end up with is too ambiguous and you'll need type annotations: E.g. what is the type of the term "2+3"? It is something like "Num a => a" (read: any type that is roughly number-like), but that is not useful if you want to run the program. However, in practice you won't need an annotation in almost all cases as long as some function you work with restricts the type. 2) Some Haskell extensions increase ambiguity in certain cases. |
|
I don't think your example works in the case of OCaml since the signature of (+) is int -> int -> int. Basic operators not being polymorphic is one of the specificities of OCaml.