Re: [Haskell-cafe] pointer equality

2011-07-21 Thread Dean Herington
For the following expression, I would consider a True result a false positive: let x = x :: Int in x == x Dean ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] pointer equality

2011-07-21 Thread Pedro Vasconcelos
On Wed, 20 Jul 2011 12:48:48 -0300 Thiago Negri evoh...@gmail.com wrote: Is it possible to implement (==) that first check these thunks before evaluating it? (Considering both arguments has pure types). E.g., Equivalent thunks, evaluates to True, does not need to evaluate its

Re: [Haskell-cafe] pointer equality

2011-07-21 Thread Steffen Schuldenzucker
On 07/21/2011 10:30 AM, Pedro Vasconcelos wrote: On Wed, 20 Jul 2011 12:48:48 -0300 Thiago Negrievoh...@gmail.com wrote: Is it possible to implement (==) that first check these thunks before evaluating it? (Considering both arguments has pure types). E.g., Equivalent thunks, evaluates to

Re: [Haskell-cafe] pointer equality

2011-07-21 Thread Alexey Khudyakov
Any examples for hangups of 'smartEq' are greatly appreciated, I couldn't produce any so far. Following sequences will hang smartEq. They are both infinite and aperiodic. smartEq (fromList primes) (fromList primes) smartEq (fromList pidigits) (fromList pidigits)

Re: [Haskell-cafe] pointer equality

2011-07-21 Thread Steffen Schuldenzucker
On 07/21/2011 02:15 PM, Alexey Khudyakov wrote: Any examples for hangups of 'smartEq' are greatly appreciated, I couldn't produce any so far. Following sequences will hang smartEq. They are both infinite and aperiodic. smartEq (fromList primes) (fromList primes) smartEq (fromList pidigits)

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread yi huang
2011/7/20 Eugene Kirpichov ekirpic...@gmail.com reallyUnsafePointerEq#, and it really is as unsafe as it sounds :) Why is it so unsafe? i can't find any documentation on it. I think always compare pointer first is a good optimization. 20.07.2011, в 7:51, Nikhil A. Patil

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread Carl Howells
On Tue, Jul 19, 2011 at 11:14 PM, yi huang yi.codepla...@gmail.com wrote: 2011/7/20 Eugene Kirpichov ekirpic...@gmail.com reallyUnsafePointerEq#, and it really is as unsafe as it sounds :) Why is it so unsafe? i can't find any documentation on it. I think always compare pointer first is a

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread Levent Erkok
Is there any way of getting the following code to immediately return True without performing the element-by-element comparison? Essentially this boils down to checking whether pointers are equal before comparing the contents. main = print $ f == f where f = [1..10^9] Nikhil, As

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread David Barbour
On Tue, Jul 19, 2011 at 11:14 PM, yi huang yi.codepla...@gmail.com wrote: 2011/7/20 Eugene Kirpichov ekirpic...@gmail.com reallyUnsafePointerEq#, and it really is as unsafe as it sounds :) Why is it so unsafe? i can't find any documentation on it. I think always compare pointer first is a

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread Levent Erkok
On Jul 19, 2011, at 11:34 PM, Levent Erkok wrote: import System.Mem.StableName areEqual :: Eq a = a - a - IO Bool areEqual x y = do sx - hashStableName `fmap` (x `seq` makeStableName x) sy - hashStableName `fmap` (y `seq` makeStableName y) return $ (sx == sy) || x == y One

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread Bertram Felgenhauer
Carl Howells wrote: On Tue, Jul 19, 2011 at 11:14 PM, yi huang yi.codepla...@gmail.com wrote: 2011/7/20 Eugene Kirpichov ekirpic...@gmail.com reallyUnsafePointerEq#, and it really is as unsafe as it sounds :) Why is it so unsafe? i can't find any documentation on it. I think always

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread Thiago Negri
Hello all, I'm a newbie at Haskell and I was not aware of this problem. So, equality comparison can run into an infinite-loop? My current knowledge of the language tells me that everything is Haskell is a thunk until it's value is really needed. Is it possible to implement (==) that first check

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread quick
Quoting Thiago Negri evoh...@gmail.com: Hello all, I'm a newbie at Haskell and I was not aware of this problem. So, equality comparison can run into an infinite-loop? Yes, comparing infinite lists is a non-terminating computation. My current knowledge of the language tells me that

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread Antoine Latter
On Wed, Jul 20, 2011 at 10:48 AM, Thiago Negri evoh...@gmail.com wrote: Hello all, I'm a newbie at Haskell and I was not aware of this problem. So, equality comparison can run into an infinite-loop? My current knowledge of the language tells me that everything is Haskell is a thunk until

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread Chris Smith
On Tue, 2011-07-19 at 23:33 -0700, Carl Howells wrote: False positives and false negatives are both possible, depending on GC timing. Don't use it, unless you know why it can result in both false positives and false negatives, and you know why neither of those are bad for your use case. Can

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread Brandon Allbery
On Wed, Jul 20, 2011 at 13:22, Chris Smith cdsm...@gmail.com wrote: On Tue, 2011-07-19 at 23:33 -0700, Carl Howells wrote: False positives and false negatives are both possible, depending on GC timing. Don't use it, unless you know why it can result in both false positives and false

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread Chris Smith
On Wed, 2011-07-20 at 13:32 -0400, Brandon Allbery wrote: I think it's more correct to say that the compiler is free to do things that would lead to false positives if it knows that it's safe to do so (and purity means it can find more of those cases, and more of them *will* be safe) — but

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread David Barbour
On Wed, Jul 20, 2011 at 10:40 AM, Chris Smith cdsm...@gmail.com wrote: I have looked up crowbar in a number of dictionaries of slang and informal usage... and still have no idea what you just said. Can you reword it? Crowbars offer 'leverage'. The point, I think, is that if pointer

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread Niklas Larsson
have not updated the first pointer yet.  But if that's the case, and it's executing arbitrary user code that may refer to that memory, then the garbage collector contains race conditions! Not necessarily, if the garbage collection and the move happened between taking the pointers of the two

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread Brandon Allbery
On Wed, Jul 20, 2011 at 13:40, Chris Smith cdsm...@gmail.com wrote: On Wed, 2011-07-20 at 13:32 -0400, Brandon Allbery wrote: of them *will* be safe) — but there is no way for it to crowbar pointer equality tests in that case. I have looked up crowbar in a number of dictionaries of slang

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread Bertram Felgenhauer
David Barbour wrote: On Wed, Jul 20, 2011 at 10:40 AM, Chris Smith cdsm...@gmail.com wrote: The point, I think, is that if pointer equality testing really does what it says, then there shouldn't *be* any correct implementation in which false positives are possible. It seems the claim is

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread Paul Johnson
I would have thought that the compiler, as a matter of optimisation, could insert a check to see if (==) is comparing an object with itself. The only way I can see this breaking is with perverse instances of Eq that would return False for f == f. Paul. On 07/20/2011 04:51 AM, Nikhil A.

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread wren ng thornton
On 7/20/11 5:08 PM, Paul Johnson wrote: I would have thought that the compiler, as a matter of optimisation, could insert a check to see if (==) is comparing an object with itself. The only way I can see this breaking is with perverse instances of Eq that would return False for f == f. Like

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread wren ng thornton
On 7/20/11 1:22 PM, Chris Smith wrote: If the latter, then it seems this would be a pretty serious garbage collector bug, and that it would be impossible that such a bug wouldn't also break other code that doesn't use pointer equality at all. After all, we've got a running user thread, which

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread Richard O'Keefe
On 21/07/2011, at 9:08 AM, Paul Johnson wrote: I would have thought that the compiler, as a matter of optimisation, could insert a check to see if (==) is comparing an object with itself. The only way I can see this breaking is with perverse instances of Eq that would return False for f

Re: [Haskell-cafe] pointer equality

2011-07-20 Thread Brandon Allbery
On Wed, Jul 20, 2011 at 23:53, Richard O'Keefe o...@cs.otago.ac.nz wrote: On 21/07/2011, at 9:08 AM, Paul Johnson wrote: I would have thought that the compiler, as a matter of optimisation, could insert a check to see if (==) is comparing an object with itself. The only way I can see this

[Haskell-cafe] pointer equality

2011-07-19 Thread Nikhil A. Patil
Hi, Is there any way of getting the following code to immediately return True without performing the element-by-element comparison? Essentially this boils down to checking whether pointers are equal before comparing the contents. main = print $ f == f where f = [1..10^9] Thanks!! nikhil

Re: [Haskell-cafe] pointer equality

2011-07-19 Thread Brandon Allbery
On Tue, Jul 19, 2011 at 23:51, Nikhil A. Patil patil.nik...@gmail.comwrote: Is there any way of getting the following code to immediately return True without performing the element-by-element comparison? Essentially this boils down to checking whether pointers are equal before comparing the

Re: [Haskell-cafe] pointer equality

2011-07-19 Thread Eugene Kirpichov
reallyUnsafePointerEq#, and it really is as unsafe as it sounds :) 20.07.2011, в 7:51, Nikhil A. Patil patil.nik...@gmail.com написал(а): Hi, Is there any way of getting the following code to immediately return True without performing the element-by-element comparison? Essentially this