8 ms·
Bartosz Milewski argues that we can think of functions etc. as containers as well, if you check out his YouTube lectures on Category Theory for Programmers. Lis
by adamddev1 2y ago
Bartosz Milewski argues that we can think of functions etc. as containers as well, if you check out his YouTube lectures on Category Theory for Programmers. Lists and functions "contain" a type.
- jerf 2y agoA term's utility comes from its ability to separate things into different categories. A definition of "container" that includes everything is therefore useless, because if everything a container, there is no information in the statement that something is a container. In Bartosz's case he's probably making the precise point that we can abstract out to that point and that at a super, super high level of category theory, there isn't anything that isn't a container. However, that's a didactic point, not a general truth. In general we programmers generally do mean something by the word "container", and functors can indeed include things that are therefore not containers. Moreover, I would say it's not what the author was thinking. The author is not operating on that super high level of category theory.
- edflsafoiewq 2y agoA list [b] is a container for bs indexed by integers. A function a->b is a container for bs indexed by as.
- cluckindan 2y ago[b] is more like a blueprint for a container, and a->b is more like an assembly line of containers.
- rebeccaskinner 2y ago> A function a->b is a container for bs Anecdotally, this is one of those things that's trivially true to some people, but really hard for other people to internalize. I think it's why the "container" can lead people astray- if you haven't internalized the idea of functions as being indexed by their argument, it's a really mind twisting thing to try to make that leap.
- n_plus_1_acc 2y agoI can recommend learnung some scala, where HashMap extends PartialFunction
- rebeccaskinner 2y agoI've never looked at scala, but that's really interesting. Do you find that's useful in practice?
- magicalhippo 2y agoIf I give you a function "f(x) := 3 * x", is it really that useful to talk about it as a container of the natural numbers? The reverse though is useful, a container looks like a function that takes one or more indices and returns a value or element.
- rebeccaskinner 2y agoI think that understanding the (moral) equivalence is useful in both directions. In particular, I think helping people understand the "function-as-container" analogy is a useful way for people to understand pure functions- another thing that's conceptually simple but a lot of people struggle to really wrap their mind around it.
- magicalhippo 2y agoPersonally I would say it muddies the water for me, as "container" has strong connotations in other directions. But then I've never thought the concept of a pure function to be particularly difficult, despite growing up on procedural languages. It's other bits that I struggle with when it comes to functional programming.
- mncharity 2y ago> really hard [...] leap Two stepping stones might be array getters (function that's array-ish), and arrays with an indexed default value function (array that's function-ish)?