2 ms·
He's criticized the lack of a generic print function, calling it "a face-smashing insult to usability." http://steve.yegge.googlepages.com/when-polymorphism-fa
by rkts 19y ago
He's criticized the lack of a generic print function, calling it "a face-smashing insult to usability."
http://steve.yegge.googlepages.com/when-polymorphism-fails http://steve.yegge.googlepages.com/when-polymorphism-fails
Note that like many of the alleged deficiencies of OCaml, this was a compromise for performance.
- mfp 19y agoGood find. I don't see how this keeps OCaml "from being a first choice for server-side development" while making it an acceptable language for client-side development, though. There are a several hackish polymorphic print implementations, but the best solution so far seems to be the "deriving" camlp4 extension (http://code.google.com/p/deriving/wiki/Introduction http://code.google.com/p/deriving/wiki/Introduction). This looks pretty good: type 'a tree = Leaf of 'a | Branch of 'a tree * 'a * 'a tree deriving (Show) type point = { x : float; y : float } deriving (Show) let points = Branch (Leaf {x=0.0; y=0.0;}, {x=2.0; y=2.0}, Branch (Leaf {x=1.0; y=1.0}, {x=1.0; y=0.0}, Leaf {x=0.0; y=1.0})) Show.show<point tree> points => "Branch (Leaf {x =0.; y =0.}, {x =2.; y =2.}, Branch (Leaf {x =1.; y =1.}, {x =1.; y =0.}, Leaf {x =0.; y =1.}))"