natefaubion / purescript-spork

Elm-like for PureScript
MIT License
157 stars 9 forks source link

Comparison of the thunks created by functions thunk2 and thunk3 always returns false #2

Closed dederer closed 6 years ago

dederer commented 6 years ago

Hi,

If thunks are created using the function thunk2 or thunk3, then comparing them with unsafeEqThunk always returns false.

unsafeEqThunk ∷ ∀ f i. Thunk f i → Thunk f i → Boolean
unsafeEqThunk (Thunk a) (Thunk b) =
  runExists' a \t1 →
    runExists' b \t2 → case t1, t2 of
      Thunk' _ c r arg, Thunk' _ c' r' arg' →
        reallyUnsafeRefEq c c' && reallyUnsafeRefEq r r' && c' arg arg'
                                  ^^^^^^^^^^^^^^^^^^^^^^

As far as I understand, the values of r and r' in expression reallyUnsafeRefEq r r' are anonymous functions (\{ _1, _2 } → f _1 _2) and their comparison always returns false.

thunk2 ∷ ∀ a b f i. Fn.Fn3 (a → b → f i) a b (Thunk f i)
thunk2 =
  let
    comp a b =
      reallyUnsafeRefEq a._1 b._1 && reallyUnsafeRefEq a._2 b._2
  in Fn.mkFn3 \f a b →
    Fn.runFn3 thunk comp (\{ _1, _2 } → f _1 _2) { _1: a, _2: b }
                         ^^^^^^^^^^^^^^^^^^^^^^^
natefaubion commented 6 years ago

Ah! I think you are correct. Thanks for the bug report. We could probably add another slot in the constructor to "unpack" it like we are doing for comp, rather than wrapping the render function directly.