State of DData

Keith Wansbrough Keith.Wansbrough at
Fri Mar 26 12:30:33 EST 2004

> > > Does the bias matter at all if Eq means equality?
> >
> > It should be documented, so "advanced users" can rely on the behaviour.
> In my opinion, even "advanced users" should adhere to The Haskell Report which 
> says that (==) means equality.

Sorry, not sure what happened with my previous reply.  Here it is again:

  data Foo = Foo Int Int

  instance Eq Foo where
    (Foo x _) == (Foo y _) = x == y

  mkFoo x = Foo x (expensive_calculation x)
  fooX (Foo x _) = x
  fooY (Foo _ y) = y

  a = mkFoo 10
  b = mkFoo 10

  m = if fooY a > 10 then add a empty else empty
  m' = add b m

Now it would be nice to know that a is in the collection, not b,
because a's Y component has been forced, but b's hasn't.  Replacing a
with b would waste work.

Thus knowing the bias may be important for time/space analysis.

--KW 8-)

Keith Wansbrough <kw217 at>
University of Cambridge Computer Laboratory.

More information about the Libraries mailing list