Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] Subtyping structurally-equivalent records, or something like it?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: AUGER Cédric <Cedric.Auger@l...>
Subject: Re: [Caml-list] Re: Subtyping structurally-equivalent records, or something like it?
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.

So general functions should use a kinematic -> [Type]
and a specialized function, force -> [Type] and so on...

I understand this version is not as handy as the phantom types, as we
need to use "match ... with Force f -> ..." or at least "let Force f
= ... in ...", but my question is only in terms of efficiency;
obviously phantom types are more or equally efficient than what I
exposed, but does the reciproque also holds?