Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>No, what you are asking for is known in the Haskell world as <em>referential identity</em>: the idea that for two values of a certain type, you can check whether they are the same value in memory or two separate values that happen to have exactly the same properties. </p> <p>For your example, you can ask yourself whether you would consider the following two values the same or not:</p> <pre><code>pl1 :: Point Int pl1 = Point 0 (Point 0 pl1 1) 1 pl2 :: Point Int pl2 = Point 0 pl2 1 </code></pre> <p>Haskell considers both values completely equal. I.e. Haskell does <strong>not</strong> support referential identity. One of the reasons for this is that it would violate other features that Haskell does support. It is for example the case in Haskell that we can always replace a reference to a function by that function's implementation without changing the meaning (equational reasoning). For example if we take the implementation of <code>pl2</code>: <code>Point 0 pl2 1</code> and replace <code>pl2</code> by its definition, we get <code>Point 0 (Point 0 pl2 1) 1</code>, making <code>pl2</code>'s definition equivalent to <code>pl1</code>'s. This shows that Haskell cannot allow you to observe the difference between <code>pl1</code> and <code>pl2</code> without violating properties implied by equational reasoning.</p> <p>You could use unsafe features like <code>unsafePerformIO</code> (as suggested above) to work around the lack of referential identity in Haskell, but you should know that you are then breaking core principles of Haskell and you may observe weird bugs when GHC starts optimizing (e.g. inlining) your code. It is better to use a different representation of your data, e.g. the one you mentioned using a <code>Maybe Point</code> value.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload