State of DData

Wolfgang Jeltsch wolfgang at jeltsch.net
Fri Mar 26 14:17:26 EST 2004


Am Freitag, 26. März 2004 13:30 schrieb Keith Wansbrough:
> > > > 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-)

Ok, you're right.

But a bias specification should not be needed to know what the result of the 
add function is semantically.  A bias spec is, of course, needed for Map.add.

Wolfgang



More information about the Libraries mailing list