core icon indicating copy to clipboard operation
core copied to clipboard

[Refactor] migrate `immut/list` to destination passing style

Open peter-jerry-ye opened this issue 10 months ago • 8 comments

Motivation

In short: avoid stack overflow for operations such as map.

Solution

Make the structure mutable while not exposing the mutability to the outside world by using pub constructor (instead of pub(all).

Ref: tail modulo constructor Impl: Stack Safe List

Migration

  • [x] add a new list package
  • [ ] deprecate the immut/list package

peter-jerry-ye avatar Apr 15 '25 03:04 peter-jerry-ye

This will break a lot of code. Can we support mut(priv) so that mutability is only allowed in package level? /cc @bobzhang

hackwaly avatar Apr 15 '25 14:04 hackwaly

What's the use case of immut/list, while there's immut/array, except for tutorial? It's less efficient and has fewer utilities, and suffers from the overflow.

In Scala for example I think the majority people would use Vector instead of List.

peter-jerry-ye avatar Apr 16 '25 01:04 peter-jerry-ye

What's the use case of immut/list, while there's immut/array, except for tutorial? It's less efficient and has fewer utilities, and suffers from the overflow.

immut/list has guaranteed O(1) complexity for cons and uncons instead of amortized, and it has pattern matching.

Yu-zh avatar Apr 16 '25 02:04 Yu-zh

I've tested list that performs nearly identical to array on iter and cons if it's elements constructed in a batch.

hackwaly avatar Apr 16 '25 06:04 hackwaly

So the current plan would be adding a new list package and deprecate the immut/list afterwards because:

  1. It's impossible to migrate gradually since the new constructor would contain labelled argument and would break everything
  2. We want to make it easier to access

peter-jerry-ye avatar Apr 16 '25 08:04 peter-jerry-ye

List constructing without cons operator is painful. Will we consider add a cons operator for list like data structures?

hackwaly avatar Apr 18 '25 06:04 hackwaly

Solution

Make the structure mutable while not exposing the mutability to the outside world by using pub constructor (instead of pub(all).

User can use @list.unfold to construct list from left to right.

illusory0x0 avatar Apr 28 '25 07:04 illusory0x0

We'll add deprecation on type (or methods)

peter-jerry-ye avatar Jun 20 '25 08:06 peter-jerry-ye