Haskell/Scala. Huge fan of pure functional programming. Here’s another comment I wrote about some FP-related things
Haskell/Scala. Huge fan of pure functional programming. Here’s another comment I wrote about some FP-related things
I think the dislike for Functors/Monads/Monoids etc. is super overrated. I’m not a mathematician, but christ these are beautiful abstractions coming from a background in Java and OO programming.
Functor instances are defined by one function. Once you learn the one main thing that Functors do (mapping), you’ll understand them no matter the language. Monoids have 2, Monads have 2, etc. Yes all there are functions built in terms of the functions required in the typeclass definitions (or several typeclasses), but they don’t need to be known to effectively use the abstractions.
I was able to easily transfer most of my Haskell knowledge to Scala at my last job in the typelevel ecosystem because of HKTs like Functors, Monads, monad comprehensions, Monoids, etc. I was the go-to guy for FP-related questions despite most of my background being in Haskell and not Scala.
Using an Iterable in Java will be different than an Iterable in any other language in at least some respects. Yes they will represent the same abstract idea, but you can’t just 1:1 transfer knowledge between different Iterable implementations.
I’ve programmed professionally in Java, Kotlin, Scala, Ruby, Python, JS/TS, and many more in hobbyist settings, and the cleanest transition was Haskell -> Scala (omitting language transitions on the same runtime, so Java -> Kotlin or JS -> TS).
Most people aren’t practicing teachers, so it makes sense that not all explanations are the best. Trying to get an intuitional understanding of passing by reference or passing by value in imperative languages is arguably more important than understanding how
map
works, and yet I’d argue it’s also harder to do.If you understand
map
(not just lists, but futures, IOs, Options, Maybes, etc.) then you understand Functors. Yes there are laws, but mathematical laws here are just encoding our intuition. Something like Iterator in Java may not have laws, but you would expect that calling.next()
doesn’t modify an SQL database, though it wouldn’t be a technically invalid implementation if it did. The same is not true for Functors. If youmap
over a List and the act of mapping each int to its double modified a database then you wouldn’t have a lawful functor. But that should make sense intuitionally without knowing the laws.People in OO land are more happy to say they “understand” something if they generally get what the abstraction is going for. Do you know all the methods for Iterator/Iterable in Java? Even if you didn’t, you’d likely say you get the “point” of an Iterable. The bar for understanding things in the FP community is usually higher than just understanding the point of something.
This doesn’t mean FP is more complicated. Actually it kind of means it’s simpler, because it’s not unreasonable for people to totally understand what Functors are for all languages that implement them. The same is not true of Iterable/Iterator. There’s no way you’d have more than just an intuition about what Iterable is in a language you don’t know. I don’t program in Agda or Idris, but I know
Functor
in those languages are the same as Functor in Scala and Haskell. Same with Monad, Monoids, etc.