Functors.jl icon indicating copy to clipboard operation
Functors.jl copied to clipboard

One-argument `fmapstructure(x)`

Open mcabbott opened this issue 3 years ago • 9 comments

Maybe this should be called fstructure(x) since there's no map. The point is to strip all the types for saving etc. Apparently others believe this method should exist: https://discourse.julialang.org/t/how-to-load-bson-file-of-the-model-build-with-flux-0-12-10-to-use-with-flux-0-13-flux-diagonal-deprecated-problem/91588/2

PR Checklist

  • [ ] Tests are added
  • [ ] Documentation, if applicable

mcabbott avatar Dec 13 '22 21:12 mcabbott

Could we find a more descriptive name by ditching the f<verb> convention here? Frankly it only made sense for functions which might've been confused for Base ones, and otherwise mostly serves to confuse folks who don't know about FP idioms.

ToucheSir avatar Dec 15 '22 16:12 ToucheSir

Is structure(x) going to be confusing next to destructure which isn't the opposite? Other words... plain or simple etc?

mcabbott avatar Dec 15 '22 18:12 mcabbott

As long as it isn't exported I don't see an issue. We've been given to using "restructure" as the inverse of "destructure", after all. That said, made up verbs like "structurize" might also work.

ToucheSir avatar Dec 15 '22 23:12 ToucheSir

Jax uses tree_structure to return the treedef. I think it could be confusing to use *structure both in verb and noun form. Could we do structural_def(x) or structural(x) to imply that we are keeping the structural definition of the tree?

darsnack avatar Apr 12 '23 19:04 darsnack

What I don't like about fmapstructure as a name (in any form) is that the "structures" are precisely what it does not preserve. It preserves the graph of children, it uses only Base objects...

mcabbott avatar Apr 25 '23 00:04 mcabbott

What about tree_def(x) or graph_def(x)? So "give me the graph definition that underlies these nested structures."

darsnack avatar Apr 25 '23 13:04 darsnack

There has got to be a nice name somewhere. They aren't strictly trees due to cache. "simple" or "strip" or "raw"... It's basically a recursive application of children, does that go anywhere, "family", "grandkids"?! child_graph(x)?

mcabbott avatar Apr 25 '23 13:04 mcabbott

I think any ancestral tree/graph analogies beyond referring to the parent/children of a single node is confusing. I am okay with something like strip or simplify (or the noun versions).

darsnack avatar Apr 25 '23 16:04 darsnack

fstructure feels consistent for this.

CarloLucibello avatar Mar 09 '24 18:03 CarloLucibello