Live data from Hacker News

Ask HN: How to be fluent in functional language speak?

news.ycombinator.com

51–60 of 112 posts

Re: Ask HN: How to be fluent in functional language speak?

#51

"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, Map…

> 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"?

Because names don’t carry meaning, they’re pointers: 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.

Re: Ask HN: How to be fluent in functional language speak?

#52
post #47

Simply, read this: https://fsharpforfunandprofit.com/fppatterns/ Then: https://fsharpforfunandprofit.com/rop/ Then if wanna go round: https://fsharpforfunandprofit.com/series/thinking-functional... Ok, almost all that site. is truly good.

Scott Wlaschin (the author of that site) does an amazing job of explaining functional programming concepts, and I highly recommend both his site and his book, "Domain Modeling Made Functional". But he does usually try to avoid words like "monad" and "functor", so you might not pick up fluency in the mathematically-inspired vocabulary from this particular resource.

Re: Ask HN: How to be fluent in functional language speak?

#53
post #14

Give up while you can. Immutable data classes and functional pipelines are great, everything else isn't worth it. Lots of people say FP is amazing but very few people use it in the real world because like you say, its unintelligible.

I use FP everyday, but I'm not an academic and I couldn't tell you what a monad is. But I do know about closures, lambdas, filter, map, reduce, arity and other basic concepts. I prefer to write functions instead of classes (JS/TS). So I'm not a wizard, but FP is helpful even at an elementary level

Re: Ask HN: How to be fluent in functional language speak?

#54
post #36

I also dislike unnecessary use of programming jargon. A type constructor is all the possible ways to make a value of that type. For example: type answer = | Yes | No | Maybe The type is 'answer'. The constructors are Yes, No, and Maybe (these are actually called type variants but now we're getting into jargon). I presume an 'abstraction over type constructors' means you want to generalize that type, so you can use th…

This is wrong, those variants are value constructors. The type constructor there is “answer,” there’s only one of them.

So type constructors take types as their parameters and return new types you're saying, whereas the variant type in my example, the values are the constructors that make up the value of Type Answer

Re: Ask HN: How to be fluent in functional language speak?

#55
post #36

Earlier quoted context omitted.

This is wrong, those variants are value constructors. The type constructor there is “answer,” there’s only one of them.

So type constructors take types as their parameters and return new types you're saying, whereas the variant type in my example, the values are the constructors that make up the value of Type Answer

That's right. Type constructors are related to generics. For example if you have a generic type `List` you could think of `List` as a type constructor.

In most languages, however, that's not a construct you can do much of anything with.

Re: Ask HN: How to be fluent in functional language speak?

#56

Question to all the functional programming experts: When OOP got introduced people started building all these elaborate object hierarchies and design patterns only to find out after a while that simpler is better and most features should be used rarely or never. Is there also a risk with FP too that people fall a little too much in love with “elegant” code only to find out later that maybe simpler is better? Reading…

There's been a "simpler is better" conversation bouncing around the FP community as well lately.

Jumping on all the shiny-new-feature bandwagons that makes code drift towards unnecessary complexity, even if it technically makes things "better" given some sort of objective context, is something a team working with these languages really needs to consider.

Re: Ask HN: How to be fluent in functional language speak?

#57
post #45

Earlier quoted context omitted.

> The hardcore “sound types” crowd believes that anybody using dynamic types is doomed. What they believe is that "dynamic types" is a misnomer, and if you think your program is checking dynamic types, it is in fact doing runtime pattern matching over a variant record. There's nothing wrong with pattern matching and variant records; but conflating them with types is just nutty, and using them pervasively as part of t…

I don’t think many people programming in dynamic languages would die on that hill. Avoiding types is kind of the allure, I think?

At the expense of having to write more tests that a type system could have solved at compile time, and likely catch more runtime logic bugs as well.

For the record I am a convert. Types have made my developer life much happier, especially working with unfamiliar code across multiple projects/teams. When you treat your builds as long term proofs your confidence level increases dramatically.

Re: Ask HN: How to be fluent in functional language speak?

#58

Earlier quoted context omitted.

> 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"?

To 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]:…

All 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.

Re: Ask HN: How to be fluent in functional language speak?

#59

Earlier quoted context omitted.

> 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"?

Because names don’t carry meaning, they’re pointers: 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…

Well, 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.

Re: Ask HN: How to be fluent in functional language speak?

#60
post #8

Most of the jargon denotes straightforward definitions. Pick the top-most frequent three terms, e.g. monad, monoid, applicative, write down the definition + a small example on a card, lather rinse repeat a few times and you're golden. Edit. For example, let's take 'catamorphism'. Read the Wikipedia entry [0] and it's a seemingly never ending jungle of more and more abstract terms. Homomorphism, initial algebra, F-alg…

> Read the Wikipedia entry [0] and it's a seemingly never ending jungle of more and more abstract terms.

Yup, category theory is often called "general abstract nonsense" precisely because it manages to talk about many disparate parts of math (or programming!) in a way that purposely avoids any reference to the specific. To usefully interpret the above, you specifically need to know that your domain often uses the category (C) of types (as objects) and functions (as morphisms), and that this category features certain generic types (such as Option, List, Array etc.) as endofunctors - and then literally plug all of those into the definition and work out the result.

It's exactly the difference between (in an elementary context) a word problem, vs. the general theory of equations of type foo which could be used to solve any number of word problems - except replicated at a higher level.

Post reply on HN