top | item 39927481

(no title)

kamov | 1 year ago

This isn't quite right, linked lists and trees in functional languages can be represented extremely succintly, i.e.

  data List a = Nil | Node a (List a)
  data Tree a = Leaf a | Node (Tree a) (Tree a)
there is nothing stopping you from writing something like this in JS

  const list = { kind: 'node', val: 3, next: { kind: 'nil' } };
And then using a switch case to navigate the list/tree matching on the kind field.

discuss

order

recursive|1 year ago

Absolutely. The navigation behaviors will have to be in functions though. And from an application code developer's perspective, the connection between these objects and functions may not be obvious. If only there were some way to associate behavior with state.

lioeters|1 year ago

The whole point of the top comment is that they appreciate how this library chose not to associate behavior with state, and instead organized things as functions and data structures.

With the latter approach, the user is not limited to the bahaviors that the library author wrote. The data (not state) can be used freely. Similarly, the functions are not tied to any particular state - the data can come from anywhere, as long as it has the right shape.