Andreas C. Doering wrote:

 | I would like to have a comparison instruction that compares the internal
 | reference of two objects. 

It might be of interest here to talk about a paper that Dave Sands and I
have recently submitted to a conference, about something we call
"observable sharing".

It talks about an extension to Haskell that we made in order to
describe hardware circuits in Haskell in a convenient way. So we present a
different solution to the problem that O'Donnel describes in [1].

The contructs we add to the language are:

  type Ref a = ...

  ref   :: a -> Ref a
  deref :: Ref a -> a
  (<=>) :: Ref a -> Ref a -> Bool

This basically gives you ML-style but non-updatable references, but you
can compare them for equality. You can also see it as pointer equality,
but only on objects of a certain type, so that you have to explicit at
creation time if you want to pointer-compare them later.

  let x = ref 27 in x <=> x

yields True, whereas

  ref 27 <=> ref 27

yields False.

So, it does break referential transparency.

But, in the paper, we show that very many transformations that a compiler
may safely perform in normal Haskell can still be performed in Haskell
with the extension.

In fact, *all* the laws from Moran's and Sand's paper about the Lazy
Improvement Theory [2] still hold in Haskell with the Ref extensions! 

If you want a (draft) copy of the paper, let me know.

Regards,
Koen.

References:

[1] O'Donnell, J., Generating netlists from executable circuit
    specifications in a pure functional language, Functional Programming
    Glasgow, 1993.

[2] Moran, A. and Sands, D., Improvement in a Lazy Context: An Operational
    Theory for Call-By-Need, POPL '99, 1999.

--
Koen Claessen         http://www.cs.chalmers.se/~koen     
phone:+46-31-772 5424      e-mail:[EMAIL PROTECTED]
-----------------------------------------------------
Chalmers University of Technology, Gothenburg, Sweden



Reply via email to