On 04-05-2010, AUGER Cédric <cedric.au...@lri.fr> wrote: > I am not expert in Ocaml, is the following the same in terms > of performances as the phantom types? > > type kinematic = ... > > type force = Force of kinematic > type momentum = Moment of kinematic > ... > > That is does the constructor introduce an overhead or not? > As there is only one constructor, no overhead should be done in an > optimized compiler. >
The variants are represented using a block. If you introduce a single variant, it will create a block that points to kinematic. E.g. "Force of kinematic" will create a pointer to the kinematic structure. Your construction of force and momentum will add a level of indirection for every use of the kinematic structure. Phantom type doesn't add a level of indirection and left no trace in the generated assembler. This is not about optimized compiler in this case but about data representation. Even if you use an optimized compiler (which is not really the case with ocamlopt), you won't change datastructure representation to optimize. Regards, Sylvain Le Gall _______________________________________________ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs