Live data from Hacker News

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

news.ycombinator.com

41–50 of 112 posts

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

#41

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…

> 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

I know some functional programmers who write complex code because they want to use the latest features of the type system. They get additional type safety, or better code factorization, but it results in code that is very hard to read and maintain, especially for people not as skilled as the initial programmer.

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

#44

First, you probably don't need to read academic articles to learn about functional programming. There's really nothing magical or complicated with functional programming. For instance, Scheme or OCaml are routinely used as beginner programming languages in schools around the world. You can start with the basic concepts and eventually build your way up to more abstract constructs when you realize you need them. But ev…

Not sure about Scheme, but OCaml's type system is not powerful/expressive enough that (to use the given example) abstracting over type constructors is likely to ever come up. (No HKTs in OCaml.) Also, OCaml uses a naming scheme for certain things that I haven't seen used elsewhere - e.g. what OCaml calls a "Functor" is a parameterized module, not closely related to Functors in other languages that use that abstraction. I suspect this is a result of the French/English language divide in the initial development of OCaml vs all other major functional languages.

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

#45

Earlier quoted context omitted.

You run the risk of being lynched by the Haskell mob, with talk like that. But I agree, in principle. The hardcore “sound types” crowd believes that anybody using dynamic types is doomed. I must not have the same problems they do. First class functions; closures; higher order functions; partial function application, seasoned with the occasional variadic vs fixed arity function, and I’m good. One can learn the other 9…

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

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

#46
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…

I'd argue that 99.9% of OCaml programmers have never heard of the term "catamorphism"!

Still cool to know there's a name for it, but I wouldn't write in a code review "why don't you refactor your description function using a catamorphism".

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

#48

First, you probably don't need to read academic articles to learn about functional programming. There's really nothing magical or complicated with functional programming. For instance, Scheme or OCaml are routinely used as beginner programming languages in schools around the world. You can start with the basic concepts and eventually build your way up to more abstract constructs when you realize you need them. But ev…

Not sure about Scheme, but OCaml's type system is not powerful/expressive enough that (to use the given example) abstracting over type constructors is likely to ever come up. (No HKTs in OCaml.) Also, OCaml uses a naming scheme for certain things that I haven't seen used elsewhere - e.g. what OCaml calls a "Functor" is a parameterized module, not closely related to Functors in other languages that use that abstractio…

OCaml functors come from Standard ML, which predates Haskell. And you can definitely use them to implement HKTs — they are comparable in expressiveness to single-parameter typeclasses.

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

#49

Earlier quoted context omitted.

I had a very visceral experience of Blub in my formative years. I don't recall how old I was, certainly under 11. I was explaining to my father the many things I could do in LOGO, and he asked about arrays. LOGO supports arrays, of course, but it was beyond anything I'd dealt with. I remember that feeling of entirely not understanding why you'd want to bother with arrays instead of just making more variables.

I had a similar experience also at age 11 - I was learning C++ to solve my math homework problems. I heard about Python, tried it out, and went on IRC to ask how I could write "goto" statements in Python. I couldn't believe it when people told me they weren't necessary, and linked "Go To Considered Harmful"!

Oh man, some of my LOGO programs had so many gotos.

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

#50

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

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]: https://softwareengineering.stackexchange.com/questions/2033...

Post reply on HN