These are chat archives for ramda/ramda

26th
Dec 2015
Hardy Jones
@joneshf
Dec 26 2015 12:40
:angel:
@lucasfeliciano while an array is just a simplified version of a tree, you might benefit more from using an actual tree data type in this case.
Niloy Mondal
@niloy
Dec 26 2015 12:43
@joneshf What is an actual tree data type?
Hardy Jones
@joneshf
Dec 26 2015 12:49
@niloy looking at the images, it would have a value at the branches and at the nodes. These values could be different types.
this could still be represented with an array, mind you, but it would probably be easier if a specific data type that captured this was used.
Niloy Mondal
@niloy
Dec 26 2015 12:50
You mean a class that encapsulates it?
Hardy Jones
@joneshf
Dec 26 2015 12:50
not necessarily.
you can do it prototypally
is that a word?
Scott Sauyet
@CrossEye
Dec 26 2015 12:52
Or use a plain function to generate your type...
Niloy Mondal
@niloy
Dec 26 2015 12:52
yeh, but you would still rely on arrays
no matter how u choose to create it
Hardy Jones
@joneshf
Dec 26 2015 12:54
not necessarily, it depends on what the tree actually represents.
if you can have an arbitrary numbe rof children at each node
then yeah, ana rray makes sense for the children, but it should still be an array of trees.
if you have a specififc number of children, say 3 maximum, then no, don't use an array.
Scott Sauyet
@CrossEye
Dec 26 2015 12:57
And very common is a binary tree. There you would j just have left and right children.
No arrays in sight.
Hardy Jones
@joneshf
Dec 26 2015 13:25
word
It's too early, and I'm too sick to write an actual implementation, but finding the difference seems pretty monoidal
different nodes
erm
nodes that need to change
each branch needs to change if any of its children need to.
so fold over the children of a node with || and that tells you if a node needs to change.
I guess you need to start by marking each node for a change when you modify it.
then you can fold over it.
Hardy Jones
@joneshf
Dec 26 2015 13:35
something like this might be a good start:
data Tree val ann = Leaf ann val
                  | Branch ann (Tree val ann) (Tree val ann)
you wantt he annotation as the type variable for the Functor and stuff to operate over.
Hardy Jones
@joneshf
Dec 26 2015 14:01

And if you have a lens to the element you want to modify:

foo :: Lens (Tree val ann) (Tree val ann)

and function for modifying it:

updateFoo :: Tree val ann -> Tree val ann

.
Then you can first reset all annotations to False:

unchanged :: Tree val ann -> Tree val Bool
unchanged tree = False <$ tree

make your change:

modifyFoo :: Tree val Bool -> Tree val Bool
modifyFoo = over foo ((True <$) . updateFoo)

and find the different ones:

diffs :: Tree val Bool -> Tree val Bool
diffs = extend (getAny . foldMap Any)

.
Just throw it all together with those three functions.

forgive the haskell, but my brain isn't up to snuff for js this early or sick
that's kind of a good example though
it combines a whole bunch of these less familiar concepts.
Lenses, comonads, foldMap, etc.
while the whole of it is kind of complex, each individual part is fairly simple.
seems almost blog-worthy.
Maybe tomorrow.
Hardy Jones
@joneshf
Dec 26 2015 14:14
@lucasfeliciano So i guess one answer to your question is: you can use a tree and the Extend instance for it to find the differences.
Tobias Pflug
@gilligan
Dec 26 2015 16:57
@joneshf hope you get better soon then