efficiency

Ashley Yakeley ashley@semantic.org
Mon, 14 Jan 2002 23:07:39 -0800


At 2002-01-15 00:00, Ketil's local user wrote:

>When recently reading the GHC docs, the chapter about profiling, I
>think, I came across something about this.  From Chapter 6:
>
>| Newtypes are better than datatypes:
>|
>|    If your datatype has a single constructor with a single field,
>| use a newtype declaration instead of a data declaration. The newtype
>| will be optimised away in most cases 

Does that help?

data (,) a b = (,) a b;
newtype Pair v w a = P (v a, w a);

vs.

data Pair v w a = P (v a) (w a);

and

data () = ();
newtype Empty a = E ();

vs.

data Empty a = E;



-- 
Ashley Yakeley, Seattle WA