space efficiency question

Janis Voigtlaender voigt@orchid.inf.tu-dresden.de
Tue, 18 Dec 2001 14:22:19 +0100


Frank Dellaert asks:

> test (Instance a1 _) (Instance a2 _) = (a1==a2)
> 
> will this be implemented efficiently ? I.e. will it check first whether the > pointers happen to be the same, and only then do a full Eq comparison ?

No, otherwise you might also expect that the following test' function:

test' :: String -> Bool
test' s = (s==s)

always returns True, without considering its actual argument s. But this
is not the way of it, (==) evaluates the two strings to be compared as
far as necessary for this comparison. For example:

test' "abc" = True

but:

test' undefined = undefined

If you really need something like pointer equality, you might want to
consider the stable names of:

@inproceedings{ jones99stretching,
    author = "Simon L. Peyton Jones and Simon Marlow and Conal Elliott",
    title = "Stretching the Storage Manager: Weak Pointers and Stable
Names in Haskell",
    booktitle = "Implementation of Functional Languages",
    pages = "37-58",
    year = "1999",
    url = "citeseer.nj.nec.com/jones99stretching.html" }


--
Janis Voigtlaender
http://wwwtcs.inf.tu-dresden.de/~voigt/
mailto:voigt@tcs.inf.tu-dresden.de