7 ms·
> they only matter with GADTs and local modules Local modules (assuming this means e.g. a module passed in as a function argument, constrained to have one of i
by wyager 4y ago
> they only matter with GADTs and local modules
Local modules (assuming this means e.g. a module passed in as a function argument, constrained to have one of its types match the type of another argument) are how you write non-trivial polymorphic code.
> Atomic ... CCPair
More functors (in haskell terminology) - code that doesn't do anything interesting with the type parameter.
> What do you mean by LAT
Locally abstract type
> I am sorry to ask but are you confusing bounded polymorphism with parametric polymorphism?
Bounded polymorphism is an application of parametric polymorphism. Not sure what you are asking here. Possibly this will clarify my line of thought: I consider parametrically polymorphic code without any bounds to be "uninteresting"/"trivial", because either the code must treat the polymorphic type completely opaquely (leading to trivial functorial [in the haskell sense] operations like implementing fmap), or requiring you to explicitly pass in all supported operations on the instantiated type (basically requiring you to implement bounding by hand).
I think this may be a blub paradox thing, where the set of useful applications of PP is much more restricted in ocaml, to the point where ocamlers do not even consider what they are missing. A haskell or rust programmer would likely run into these semantic blocks quickly upon trying ocaml.
- octachron 4y agoOk, you are using "parametric polymorphism" to mean bounded polymorphism. This explain my confusion! Indeed, I can understand your point of view then: bounded polymorphism is indeed better done with functors in OCaml. And since functor are syntactically heavy in OCaml there are not used everywhere and only when they are useful. Which doesn't mean that they are not used at all, as the Mirage project can attest. MirageOS is essentially an Operating System build upon OCaml functors.
- wyager 4y agoI don't really consider those separate things. Bounded polymorphism is parametric polymorphism, plus a type subset relationship. A quick sanity check on wikipedia is consistent with this model. BP is PP plus what's required to make it more than a toy I remember one annoyance I had with ocaml was the effective inability to use point-free style. I can't remember what limitation was behind this; do you know off the top of your head? Edit: it's the "value restriction", more annoying bullshit I forgot about! Huge limitation for polymorphic ocaml code.
- yawaramin 4y ago> BP is PP plus what's required to make it more than a toy And in fact OCaml does have BP, as was explained earlier, just with a heavier syntax. > effective inability to use point-free style OK but point-free style is not an end in itself, it's just a means to an end (clean code), and there's certainly no universal agreement that it's the best means...explicit style is almost always easier to understand for a wide assortment of people and doesn't require mental backflips trying to figure out the weird heiroglyphics of '(.) (.) (.)' etc. etc. > Huge limitation for polymorphic ocaml code. Yeah I can see how writing e.g. let f x = g [] x As opposed to let f = g [] Is such a deal-breaker. /s
- wyager 4y ago> just with a heavier syntax. Ok, I'm glad we agree on that. > I can see how writing Eta reduction is one example, but a great deal of code is cleanly expressed as e.g. vecLen = sum . map (^2) And ocaml's type system is not capable of handling this gracefully. Very unfortunate!
- yawaramin 4y ago? let vec_len vec = vec |> map (fun x -> x ** 2.) |> sum Or even let square x = x ** 2. let vec_len vec = vec |> map square |> sum Honestly, if code like this is the biggest nitpick, I have a hard time taking the argument seriously.