efficiency

Ketil's local user ketil@ii.uib.no
15 Jan 2002 09:00:59 +0100


Feuer <feuer@his.com> asks about:

> newtype Empty a = E ()

vs.

> data Empty a = E

and

> newtype Pair v w a = P (v a, w a)

vs.

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

> I was wondering if anyone on this list knew of any reasons the types he
> chose would be more efficient than mine....

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 

-kzm
-- 
If I haven't seen further, it is by standing in the footprints of giants