Live data from Hacker News

Why category theory matters in programming

tech.iheart.com

41–47 of 47 posts

Re: Why category theory matters in programming

#41
post #26

> So, is there a simple and universal way to compose these functions? proceeds to add layers of complexity Why not just write a function to compose them? Argue against the competition, not strawmen.

Most code that is written has effects - null returns, error returns, exceptions, IO, etc., etc. We can write a custom function to compose every pair of functions we write, but some clever people figured out there were patterns to this madness - map, flatMap, lift, return, etc. - and it's far more efficient to write those patterns once and reuse them.

Essentially, it's DRY at a higher level of abstraction.

Re: Why category theory matters in programming

#42
post #26

> So, is there a simple and universal way to compose these functions? proceeds to add layers of complexity Why not just write a function to compose them? Argue against the competition, not strawmen.

Most code that is written has effects - null returns, error returns, exceptions, IO, etc., etc. We can write a custom function to compose every pair of functions we write, but some clever people figured out there were patterns to this madness - map, flatMap, lift, return, etc. - and it's far more efficient to write those patterns once and reuse them. Essentially, it's DRY at a higher level of abstraction.

You still have to write each composition operator separately; writing the code to compose null returns doesn't give you the code to compose IO. Only difference is whether they have separate names.

Re: Why category theory matters in programming

#43

Earlier quoted context omitted.

In my experience FP code is more buggy, but I imagine there's a lot that goes into it

What particular language are you talking about?

Mainly scala, but I've used some clojure as well. Ever since learning Go, I just haven't looked back. I think FP does well with streaming problems, but outside of that it seems to have a cognitive overhead that doesn't pay

Re: Why category theory matters in programming

#44
post #23

Earlier quoted context omitted.

Isn't a Monad just the fancy name for a type/structure that implements map and flatMap in a lawful manner?

Close: the required operations are `flatMap` and bind/pure/point/lift/return/whatever-you-want-to-call-it. You can derive `map` from these two other functions so it doesn't need to be part of the interface.

Bind is flatMap (>>=)

Confusingly, map in scala is fmap in Haskell

Re: Why category theory matters in programming

#45

Earlier quoted context omitted.

Close: the required operations are `flatMap` and bind/pure/point/lift/return/whatever-you-want-to-call-it. You can derive `map` from these two other functions so it doesn't need to be part of the interface.

Bind is flatMap (>>=) Confusingly, map in scala is fmap in Haskell

Oops you're right of course. And I can't edit my post.

Re: Why category theory matters in programming

#46
post #42

Earlier quoted context omitted.

Most code that is written has effects - null returns, error returns, exceptions, IO, etc., etc. We can write a custom function to compose every pair of functions we write, but some clever people figured out there were patterns to this madness - map, flatMap, lift, return, etc. - and it's far more efficient to write those patterns once and reuse them. Essentially, it's DRY at a higher level of abstraction.

You still have to write each composition operator separately; writing the code to compose null returns doesn't give you the code to compose IO. Only difference is whether they have separate names.

That's not the only difference. You get to reuse any code written using only those names (that interface).

Re: Why category theory matters in programming

#47

That's nice, but form a hard-nosed engineering perspective, not just sometimes, but in general 19 lines of yucky procedural code that pretty much anyone can understand (and debug) are usually way, way better than 9 lines of "elegant" functional code comparatively far fewer people can (really) understand - and which can be comparatively far more sinister and nefarious to debug. Given that, after all, it's just posting…

> hot-synching whole data centers

That is actually what Facebook is doing with their spam detection code - their purely functional architecture makes it easier and more reliable for them to hot-swap out parts of their codebase when the need to update it.

https://code.facebook.com/posts/745068642270222/fighting-spa...

Post reply on HN