purescript-unfoldable icon indicating copy to clipboard operation
purescript-unfoldable copied to clipboard

Implement Array's `Unfoldable` instance via `ST` after shuffling around dependencies

Open JordanMartinez opened this issue 2 years ago • 1 comments

If this instance was implemented via ST, then purescript-backend-optimizer would inline things when possible.

However, it seems that we can't currently do this because arrays depends on nonempty, which depends on unfoldable. AFAIK, this dependency chain exists because arrays has functions like fromNonEmpty, though I don't think anyone uses NonEmpty Array.

flowchart TD
  arrays ---> nonempty
  nonempty ---> unfoldable

If we updated arrays to depend on unfoldable and nonempty to depend on arrays, then we could add an Unfoldable instance for Array that uses ST

flowchart TD
  nonempty ---> arrays
  arrays ---> unfoldable

JordanMartinez avatar Nov 03 '23 17:11 JordanMartinez

It also seems like foldable-traversable has instances for Array written in FFI because the instance must be with the class in the same module. So, perhaps we would need to have another package like purescript-array-st where it exposes a mutable array API for use with things like this?

JordanMartinez avatar Nov 03 '23 17:11 JordanMartinez