So how does a programmer from non-functional world become fluent in understanding sentence such as "abstraction over type constructors"?
Ask HN: How to be fluent in functional language speak?
1–10 of 112 posts
Re: Ask HN: How to be fluent in functional language speak?
#2It’s been a while since I’ve dabbled with Haskell but I believe type constructors take a type and return a type (like List takes Int and returns List Int) so an abstraction over them might be an m where say m is a monad and it takes an a and gives you m a. m is an abstraction because it could be anything. A List, or Either, or State etc.
Re: Ask HN: How to be fluent in functional language speak?
#3I think your best option is to directly contact authors or very good educators and ask them exactly what they mean.
Re: Ask HN: How to be fluent in functional language speak?
#4Re: Ask HN: How to be fluent in functional language speak?
#5Are you just trying to read academic articles and blog posts? Have you tried working in one or more of the languages? Beyond "toy problems" to trying to solve larger problems?
The more you work in a language, the more you might start to understand the needs that underlie things like category theory (the mathematics of monoids, semigroups, monads, etc) and where other higher level abstractions start to play in how you want/need to write software.
There's also places to practice even in C++, Java, etc. A lot of functional programming is making its way "stealth" into even the most imperative OO languages. Are you handy with your languages map/filter/reduce libraries around iterables? Have you tried pushing that deeper towards other monads such as query transformation (Linq) or time (async/await, ReactiveX)? Have you thought about how those work under the hood? (Explored what a iterable generator or an async/await decompile to?) Have you started yet to think in terms of high level "lambdas", places where functions themselves can be reused by other objects/functions? (Beyond "callbacks" towards thinking of functions themselves as lego bricks to build with.)
There's also middle ground languages such as F# or Clojure that you can use side-by-side (in some circumstances) C# or Java (respectively) code where maybe you can't work 100% in a functional language on a project, but you can get a compromise mix.
So much of understanding the "lingo" is recognizing the patterns and/or problems to which they refer, and a lot of the easiest way you will pick up patterns and see recurring patterns is practice.
Re: Ask HN: How to be fluent in functional language speak?
#6I still remember "not getting" OO in university in my first lecture. I had programmed BASIC, C, Pascal, PHP before. And if someone would have tried to explain me the idea by means of the visitor pattern, it would surely have made me say "eh?!?" too. So allow yourself to start slowly.
I'm also still dabbling in functional programming - at least that's what it feels like reading about monoids etc - but by actually using functional programming languages in my more serious spare time projects I feel I get a better and better understanding. And "those" articles start to speak more to me.
Re: Ask HN: How to be fluent in functional language speak?
#7Re: Ask HN: How to be fluent in functional language speak?
#8Edit. 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-algebra, endomporphism. This easy, let's see what an F-algebra is [1] and we'll be on our way soon. "If C is a category, and F: C → C is an endofunctor of C, then an F-algebra is a tuple (A, α), where A is an object of C and α is a C-morphism F(A) → A.". Oh my God, this is hopeless.
Or, find a good description, with examples [2]. A 'catamorphism' card, abbreviated from [2]:
Catamorphism
A function that “collapses” a recursive type into a new value based on its structure. Visitor pattern.
Define a sum type Gift:
type Book = {title: string; price: decimal}
type Gift =
| Book of Book
| Boxed of Gift
Define a 'description' function over Gift: let rec description gift =
match gift with
| Book book ->
sprintf "'%s'" book.title
| Boxed innerGift ->
sprintf "%s in a box" (description innerGift)
Parametrize the function, creating a 'catamorphism': let rec cataGift fBook fBox gift =
match gift with
| Book book ->
fBook book
| Boxed innerGift ->
let innerGiftResult = cataGift fBook fBox innerGift
fBox innerGiftResult
Refactor your 'description' function to use a 'catamorphism': let descriptionUsingCata gift =
let fBook (book:Book) =
sprintf "'%s'" book.title
let fBox innerText =
sprintf "%s in a box" innerText
// call the catamorphism
cataGift fBook fBox gift
[0] https://en.wikipedia.org/wiki/Catamorphism[1] https://en.wikipedia.org/wiki/F-algebra
[2] https://fsharpforfunandprofit.com/posts/recursive-types-and-...
Re: Ask HN: How to be fluent in functional language speak?
#9Re: Ask HN: How to be fluent in functional language speak?
#10You will find that your fluency in almost any subject is improved with this practice.