7 ms·
"abstraction over type constructors" isn't very meaningful without more context anyway, but they're probably referring to something like the following: non-abs
by centimeter 6y ago
"abstraction over type constructors" isn't very meaningful without more context anyway, but they're probably referring to something like the following:
non-abstracted:
map :: (a -> b) -> List a -> List b
abstracted:
map :: Functor f => (a -> b) -> f a -> f b
"List" is a type constructor (it takes a type and returns a type), but we can write a "map" function that works over more types than just List - for example, Maps and Options and so on (aka "Functors" in Haskell parlance). We've "abstracted (the function map) over the type constructor (of the data structure being mapped over)".
To answer your more general question, if you just learn functional programming on a language with a powerful type system (Haskell is probably the most germane example) you will learn at least some of these terms. Most of them turn out not to be very deep, just hard to explain (for reasons unclear to those who understand them), but still very useful.
- jimbokun 6y ago> We've "abstracted (the function map) over the type constructor (of the data structure being mapped over)". Then why didn't they just call those types "Mappables"?
- jolux 6y agoBecause the concept is category-theoretic in nature and they wanted to foreground that.
- centimeter 6y agoThat would probably have been clearer to newbies, but they already had a complete terminology ready to go from category theory and it's not hard to remember "Functor ~ Mappable". Plus, "obvious" names break down once you start building up hierarchies of these properties. One of the reasons people have a hard time communicating the (simple) ideas behind other algebraic objects like Applicatives, Monads, etc. is because it's hard to come up with short, self-descriptive names for them. The search for such names has resulted in several famously bad analogies, such as "a Monad is like a Burrito".
- bojo 6y agoI think this is a great question because it tends to come up a lot. What do you call the following common operations? - 1 + 0 - 1 * 1 - "string" ++ "" - [1, 2, 3] ++ [] As far as I know there is no term for this grouping of operations outside of functional programming languages which use category theory. We call it a "monoid" based on the following precise definition: > In abstract algebra, a branch of mathematics, a monoid is an algebraic structure with a single associative binary operation and an identity element[1]. I used the "identity element" specifically in my examples above since they tend to be a good way to grasp what is going on. It turns out a "functor" has more properties than just being "mappable", which is why we like using the more precise term in our literature. However, it's still a decent intuition if you aren't familiar with the concept. For example, in the parent comment the 'f' in the second line of code shows that it is some kind of structure that adheres to a Functor, and also infers that this structure can also be mapped over. This is a nice property because without caring about the implementation, we can still do functor-specific operations over abstract structures. [1] https://en.wikipedia.org/wiki/Monoid https://en.wikipedia.org/wiki/Monoid
- pacala 6y agoconcat?
- JoshuaDavid 6y agoI can't think of any way for 1 * 1 to be concatenation. I think the point GP was making is that a monoid has something to do with a function f that takes two arguments a and b where there is a single value for b such that f(a, special_value) == a. I think. As someone who doesn't really understand FP concepts I would probably call those functions "functions that can sensibly be used in a call to array.reduce"
- pacala 6y agoIt doesn't need to have a perfect metaphor for all possible cases, just something you can picture in an instant: 'behaves like a concating variable length box sequences'. It's a mnemonic / learning aid, not a formal spec. But I can stretch it :) +: concat marbles sequence * : concat prime factors sequence ++: concat box sequence For * , it can also be reduced to + via logarithms. I just don't have a good metaphor for '+ over reals' this morning.
- bweitzman 6y agoTo be fair, the term "map" comes from math [0], and so at the time these functions were created, there weren't other good naming choices. Mappable and Functor are just about as opaque as each other if you don't know what mapping is. Though now that FP concepts are mainstream, I think there is a good case to offer some friendlier, more familiar names: Functor -> Mappable Applicative -> Pairable Monad -> Thenable [0]: https://softwareengineering.stackexchange.com/questions/203374/origin-of-common-list-processing-function-names https://softwareengineering.stackexchange.com/questions/2033...
- jolux 6y agoAll I see here is weakening the descriptive power of those terms by replacing them with more common ones. It may look easier but I think it’s probably better not to carry in baggage from other languages that doesn’t quite fit.
- whateveracct 6y agoGiving descriptive names just harms intuition building in the long run. I've been writing Haskell for over 5 years and to this day when I see <$>, <*>, >>= in my code I don't substitute English words for them.
- kortex 6y agoWas about to complain you can't google them, but I tried it and it worked. Huh. I guess you can google symbols now, even traditionally escapey-ones. News to me. mentalModel.update(). The query `python @` fails pretty hard though.
- rossng 6y agoFor Haskell stuff, you can go one better and use Hoogle: https://hoogle.haskell.org/?hoogle=%28%3C%24%3E%29&scope=set%3Astackage https://hoogle.haskell.org/?hoogle=%28%3C%24%3E%29&scope=set...
- whateveracct 6y agoI tend to just query the repl when I don't know a symbol. :info (>=>)
- agentultra 6y agoBecause names don’t carry meaning, they’re pointers: https://www.parsonsmatt.org/2019/08/30/why_functor_doesnt_matter.html https://www.parsonsmatt.org/2019/08/30/why_functor_doesnt_ma... “Functor,” points to a specific concept in Haskell and a slightly different one in Category Theory but otherwise it is fairly unambiguous given enough context. The concept not only refers to the type and the associated “map” operation but also the axioms of identity and composition and their properties. “Mappable,” is a very common name people pick in these discussions but it doesn’t clarify the meaning any more than calling it “Rose.” It may in fact cause more harm than good if a name like Mappable exists in more contexts. There are plenty of objects one can apply a map operation to that are not valid Functors.
- zozbot234 6y agoWell, Functor is a bit of a misnomer; it really should be called TypeEndofunctor. The short form was really adopted as a mischievous pun on the use of "functor" in the OOP community.
- dllthomas 6y agoI don't think TypeEndofunctor conveys any additional information when discussing a Haskell typeclass. > The short form was really adopted as a mischievous pun on the use of "functor" in the OOP community. Citation needed.
- dllthomas 6y agoI should note that naming things with mischievous puns certainly wasn't beyond early Haskellers - that's the origin of `return` as a name for part of the Monad interface (since quasi-deprecated in favor of `pure`). I just have never heard that allegation about `functor`, which seems to have been taken directly from mathematics that predate any notion of function object. It's possible that OO programmers and the mathematicians both borrowed it from the same source (it seems to have originated in linguistics).
- justinmeiners 6y ago