3 ms·
OCaml is the strongly-typed functional language that sees most serious use. It's harder to do generic polymorphism in OCaml since the language has nothing like
by chalst 6y ago
OCaml is the strongly-typed functional language that sees most serious use.
It's harder to do generic polymorphism in OCaml since the language has nothing like C++'s parametric templates or Haskell's type classes. It does have a very nice module system that has the required flexibility, but compared to these languages, I think it is clunky for the kind of genericity seen in scientific computing.
I think Julia has shown us that strong typing is not really needed for scientific computing.
- brmgb 6y ago> It's harder to do generic polymorphism in OCaml since the language has nothing like C++'s parametric templates or Haskell's type classes. It does have a very nice module system that has the required flexibility, but compared to these languages, I think it is clunky for the kind of genericity seen in scientific computing. Are parametrized modules really clunkier than parametric templates ?
- steev 6y agoAt least for beginners, they absolutely are. I have found undergrads generally get the idea behind something like HashMap<Integer, String> but getting them to reason about OCaml modules takes quite a bit of effort.
- gopiandcode 6y ago(int, string) Map.t doesn't seem to be too many steps away from your example. When I was learning OCaml, I found that much of the module and module type system can just be seen as a more beefed up version of interfaces in OOP languages, so it didn't take long to see its benefits.
- ziotom78 6y ago> I think Julia has shown us that strong typing is not really needed for scientific computing. I think you meant static typing, in opposition to dynamic. Julia is strongly typed like OCaml.
- smabie 6y agoJulia has dynamic typing, not static. You can specify types, but they don't really do anything except help with performance. A far cry from OCaml's great type inference and compile time static checking.
- ddragon 6y agoThe grandparent meant that OCaml is static while Julia is dynamic, and both are strongly typed. >You can specify types, but they don't really do anything except help with performance. For Julia it's the exact opposite though, types don't help with performance since the compiler infers them anyway regardless of declaring them or not (you only really should to specify in very particular cases where inference is not possible to avoid the compiler being too conservative, and if you overspecify types you might even end up with a slower program). You declare them for their main purpose of controlling dispatch. Julia's type system is a core aspect of it's paradigm (multiple dispatch [1]), which is the key element in both it's performance and polymorphism. It's different from a gradual typed language in which the language can exist without the types at compilation time, but those can be optionally added to enhance safety or performance, Julia cannot be compiled without knowing the types, which will happen regardless of declaration. [1] https://www.youtube.com/watch?v=kc9HwsxE1OY https://www.youtube.com/watch?v=kc9HwsxE1OY That said, types in Julia are not used for compile time static checking, which is a compromise that for many tasks it's not worth it. Ocaml ML and Julia ML can coexist well exactly because they have vastly different compromises, with Julia focused on interactivity/fast prototyping and Ocaml in safety (like Lisp x Haskell, but with somewhat more pragmatic languages).