• Nevoic@lemm.ee
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

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

    • onlinepersona@programming.dev
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      I don’t dislike them, I dislike that absolutely terrible explanations given as to what they are.

      “it’s just a function” - oh my, never would’ve guessed. The name gave nothing away.

      “given the definition, one can easily ascertain” - oh, it’s easy, isn’t it? So easy that it’s not even worth mentioning.

      “given $mathematicalDefinition, where $lotsOfOneLetterVariables, $conclusions” - yes yes, totally understood that.

      See haskell wiki, wikipedia, top blog entry #1, top blog entry #2, stackoverflow, LearnYouAHaskell

      You can’t tell me those are good ways of explaining what those are to somebody with little to no mathematical interest. Maybe the concept is easy, maybe. I mean map() is quite easy to understand, but if it were explained as badly as fmap, I guarantee you less people would use it.

      • Nevoic@lemm.ee
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        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 you map 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.