[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ocaml-dns- quick ocaml question



On Mon, Jun 18, 2012 at 07:49:28PM +0100, Richard Mortier wrote:
> 
> On 18 Jun 2012, at 19:43, Anil Madhavapeddy wrote:
> 
> > So cstruct shouldnt be a constraint; it's trivial to retarget to
> > polymorphic variants. There is a very slight performance hit, but I
> > don't think that matters.
> 
> i'll go with non-polymorphic variants for now - it's only search+replace
> - and a closed type is "better", right? 

A closed type isn't always better: especially if the underlying data
structure is actually extensible.  Would you ever need to sub-type RRs to
only have a smaller set of them? In that case, a polymorphic variant would
keep the same memory-representation, but be castable into different forms.

A closed type would have to be assigned to a new value to move between
them.  Another limitation of closed variants is that if they have
parameters (e.g. A of ipv4_addr), you can only have around 240 of them due
to the memory representation [1]. If they have no parameters, they are
limited only by integer-size.

There is a slight performance difference between normal and polymorphic
variants, due to the lack of precise type information, but it's pretty
negligible in practise (probably only for pattern-matching, really).

[1]
http://rwmj.wordpress.com/2009/08/05/ocaml-internals-part-2-strings-and-other-types/

-anil




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.