Version française
Home     About     Download     Resources     Contact us    
Browse thread
Question on writing efficient Ocaml.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] Question on writing efficient Ocaml.
From: skaller <skaller@users.sourceforge.net>
> On Thu, 2006-12-28 at 16:26 +0000, Jon Harrop wrote:
> 
> > The code is also needlessly verbose and inefficient. There's no point in 
> > declaring sum types with one contructor:
> > 
> > type posn = Posn of int * int;;
> 
> Doesn't Ocaml optimise the constructor away in this case?

It's not really an optimization, rather that Posn being a constructor
with 2 arguments (rather than a constructor taking a pair as
argument), it ends up having exactly the same representation as a
pair. So there is no loss in efficiency here.

In general, I wouldn't explicitly advise against using single
constructor type definitions for documentation, except when the
argument is a single int or float and performance matters.

Jacques Garrigue