News for hackers. Stuff that matters.
Re:Ask Hackers: Opinions on OCaml? by mfp on Saturday February 09, 2008 @07:41PM (#112840)
Good 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). 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.}))"

There are no comments on this comment yet.