by antisemiotic · 7y ago · 0 comments
What? In numeric programming we usually want the opposite, to write a function for specific type, and to make it run fast.
Also, in OCaml you can simply make your computation a parametric module of some algebraic structure, something like
module type Ring = sig
type t
val zero : t
val one : t
val (+) : t -> t -> t
...
end
module Numeric_staff (N : Ring) = struct
...
And have a completely static numeric computation without any dynamic dispatch. That's resembling C++'s templates.You also can use classes if you want dynamic dispatch
let (+) x y = x#add yThey are simply explicit. What's so clunky about modular implicits, for example?
Personally, I prefer explicit modules and hate typeclasses, because I can't look at the code and say if this operation is a primitive operator or some dynamically dispatched class method.
Besides, modules are way more powerful, and have a way broader use. They can encapsulate state, types, can be parametric etc.