Live data from Hacker News

Category Theory for Programmers (2014) [pdf]

github.com

111–120 of 136 posts

Re: Category Theory for Programmers (2014) [pdf]

#111
post #79

Earlier quoted context omitted.

Apologies. I was on the phone typing the above. Still, remarks like "What?" that provide no information or context are against the rules on HN. Just FYI. The OP said that there's no point in labeling an arbitrary type as a functor or monadic value. I'm going to use an example to illustrate how there is a benefit in being aware of this concept. I will be using a "String Monad" in my example. Imagine you have some type…

I would simply do: original_dict = {1:2 ,3:4, 5:6, 7:8} array = sum(map(list, original_dict.items()), []) And it would have been simpler if items returned lists instead of tuples. In my benchmarks it runs 10x faster.

This wasn't the point. Also map is not recommended for usage in python. Stylistically the convention says you should be using a list comprehension in place of filter and map.

Also did you do your tests with regular expressions? I specifically mentioned I didn't use regexps but it would be dramatically faster if you used it instead of the replace method.

I'll reiterate the point. The point is there is a pattern you can follow where you can move from one "type space" into another "type space" then back because the other type space may be easier to write transformations.

Obviously from the this thread, the serialized type space may not be the best way for python. But there are many other contexts where this it is better and my point is, category theory allowed me to derive this general pattern. That's it.

Re: Category Theory for Programmers (2014) [pdf]

#112

Earlier quoted context omitted.

>but it isn’t exactly as friendly to the non-mathematicians as advertised. i really chafe at criticisms like this given how much effort was clearly invested by those authors in that book being readable - there are ample definitions (and clearly offset), tons of diagrams, instructive examples, solutions to many exercises, pointers to further readings, motivation and discussion. is the thing that bothers you that there…

>is the thing that bothers you that there's formal mathematics No. I like formal mathematics. The audience of this book includes “motivated high school student who hasn’t seen calculus yet“. IMO the book fails here. The average high schooler won’t understand this book on their own. This book is excellent if you already have an understanding of abstract algebra or higher level mathematics though, which is why I said i…

compare

>The average high schooler

with

>motivated high school student

certainly we all underestimate the difficulty of material (obverse of the dunning-krueger effect) but it says it does at least hint at it right there.

but honestly i'm curious where in the book you see an example of a term or notion that isn't defined in situ? as usual (with all of these things) mathematical maturity is what's required rather than familiarity with the material. what this means is a sense for why definitions are written in the way that they are, which hypotheses in theorems capture the phenomenon and which are technical, which lemmata can be ignored on first reading, etc. this is a very hard thing to communicate, especially in text, but this book does do its best to make that not-overwhelming as possible with ample restatements of definitions and assumptions and diagrams.

Re: Category Theory for Programmers (2014) [pdf]

#113
post #104

Is there any point in learning category theory without first learning the things that it generalizes? I didn't see any value in learning about geometric algebra until I had learned enough about complex analysis to appreciate what it would mean to connect it with vector calculus.

I think category theory generalizes pretty much everything, so that may be tough.

The only thing that can generalize everything is something with no structure of its own.

Re: Category Theory for Programmers (2014) [pdf]

#114

Earlier quoted context omitted.

Apologies. I was on the phone typing the above. Still, remarks like "What?" that provide no information or context are against the rules on HN. Just FYI. The OP said that there's no point in labeling an arbitrary type as a functor or monadic value. I'm going to use an example to illustrate how there is a benefit in being aware of this concept. I will be using a "String Monad" in my example. Imagine you have some type…

Well it might use category theory and be buzzword compliant but the code you’ve written wouldn’t pass code review at my work. This code converts numeric data to a string and back to numeric data.

Buzzwords are popular words. You put category theory on your resume it's not gonna get you anything. It's obscure.

Look the point isn't the python, the point is, the design pattern can be applied to many places and in some contexts it's faster in other contexts it is not, but the design pattern exists. My intent was to convey understanding of the pattern at a very general level. Not to argue about the validity of the python implementation.

Re: Category Theory for Programmers (2014) [pdf]

#115
post #84

Earlier quoted context omitted.

Apologies. I was on the phone typing the above. Still, remarks like "What?" that provide no information or context are against the rules on HN. Just FYI. The OP said that there's no point in labeling an arbitrary type as a functor or monadic value. I'm going to use an example to illustrate how there is a benefit in being aware of this concept. I will be using a "String Monad" in my example. Imagine you have some type…

So congratulations, category theory allowed you to come up with a solution which would make you immediately fail any reasonable job interview! Compared to the obvious answer your proposed approach is more code to write, orders of magnitude slower and has security as well as potential data corruption/robustness issues. Your gloss reveals further substantial misapprehensions about python basics (there are no regexps he…

Please don't cross into personal attack, no matter how wrong or ignorant another comment is, or seems.

https://news.ycombinator.com/newsguidelines.html

Re: Category Theory for Programmers (2014) [pdf]

#116
Started reading this and was disappointed to find the same disingenuous claims about strong static type systems.

I say disingenuous because the people that espouse these beliefs seem to have a minimum modicum of intelligence and do or would certainly (after a moment of reflection) certainly realize their fallacy:

> The only serious argument I hear against strong static type check- ing is that it might eliminate some programs that are semantically cor- rect. In practice, this happens extremely rarely and, in any case, every language provides some kind of a backdoor to bypass the type sys- tem when that’s really necessary.

This is patently false. Port a correct dynamically typed program to Haskell and it will certainly fail until you satisfy the type checker through no small extraneous effort. And this is not a theoretical matter; it is an enormous cost to the programmer that is not there in weaker or non- typed systems.

It is a certainty that type systems ask for far more than is needed to produce correctness. Anyone who tries to dodge this obvious and fundamental truth is operating off of a religious not rational commitment to defending their type system. Note that I am not saying the type system doesn't give you something back but it certainly comes with a inherent cost over alternatives.

> Another argument I hear a lot is that dealing with types imposes too much burden on the programmer. I could sympathize with this sen- timent after having to write a few declarations of iterators in C++ my- self, except that there is a technology called type inference that lets the compiler deduce most of the types

This is the most heinous and sad lie. Type inference changes nothing. The types are there even if you don't have to type them in and they are significantly constraining your set of accepted programs.

I've heard this response before from seemingly smart static typers. I just can't believe a smart person would not see the obvious emptiness of this claim. There is no way anyone would think that having to type characters is the exclusive cost of static typing that inference suddenly whisks away.

I want to buy into the strong static typist's promise of utopia but I have yet to meet a static typist enthusiast that doesn't parlay in these lies, wittingly or unwittingly.

Because of this I have a serious suspicion that there is nothing else to stand on and that strong static typing is simply a case of the Emperor's New Clothes. Prove me wrong.

Re: Category Theory for Programmers (2014) [pdf]

#117
post #47

Watched that guy's lectures and conference talks. While it's quite interesting and educative - I still don't get the "for programmers" part of it. I don't quite get how I would jump from understanding categories, morphisms, monoids etc. to building actually better systems. There are zero practical examples in his talks. Is it because i'm not using functional languages or what am I missing here?

Unix pipeline a category, with text be object, and executable be morphisim converting text to text(monoid). Forth is a category, with stack as object, functions as morphisim. There are many examples. Best learn from haskell.

I could never learn what pipeline is this way.

Re: Category Theory for Programmers (2014) [pdf]

#118
post #84

Earlier quoted context omitted.

So congratulations, category theory allowed you to come up with a solution which would make you immediately fail any reasonable job interview! Compared to the obvious answer your proposed approach is more code to write, orders of magnitude slower and has security as well as potential data corruption/robustness issues. Your gloss reveals further substantial misapprehensions about python basics (there are no regexps he…

First off, I don't like your sarcastic attitude. It's against the rules on HN to do that. Don't violate rules to be rude. Second off, my example is just an example. It's not production level code. The intention of the example is to show "lifting" from from one type into another "category." The efficiency is less relevant here... in some contexts it can be faster in other contexts it could be slower or not even possib…

I timed it -- 2 orders of magnitude slower across the board.

    In [19]: short, middle, long = [{2*i+1:2*i+2 for i in range(n)} for n in [2, 2**8, 2**16]]
    In [20]: timeit  [x for kv in d.items() for x in short]
    812 ns ± 6.86 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
    In [21]: timeit  [x for kv in d.items() for x in middle]
    30.1 µs ± 1.87 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
    In [22]: timeit  [x for kv in d.items() for x in long]
    9.77 ms ± 1.19 ms per loop (mean ± std. dev. of 7 runs, 100 loops each)
    In [24]: timeit  eval(str(short).replace('{','[').replace('}',']').replace(':',', '))
    10.4 µs ± 240 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
    In [25]: timeit  eval(str(middle).replace('{','[').replace('}',']').replace(':',', '))
    592 µs ± 23.8 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
    In [26]: timeit  eval(str(long).replace('{','[').replace('}',']').replace(':',', '))
    264 ms ± 3.22 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
Python dictionaries are ordered, and iterate in order (since 3.6, as guaranteed property since 3.7). In older versions of python where they are not ordered, str also does not preserve the order in the literal (except for one of all possible orderings).

   Python 3.7.2 
   Type "help", "copyright", "credits" or "license" for more information.
   >>> str({5:6, 4:5, 3:2})
   '{5: 6, 4: 5, 3: 2}'

   Python 2.7.15
   >>> str({5:6, 4:5, 3:2})
   '{3: 2, 4: 5, 5: 6}'
You might consider what I wrote offensive, but maybe you can still take the above as evidence that there are areas where your mental model is imperfect. I have the impression there is a puzzlingly common class of CS engineering failures stemming from misguided abstraction attempts because people are either unable or just unpredisposed to making extremely back of the envelope task breakdown of the most direct implementation in terms of primitive, costed operations. I also see this happen to rather smart but inexperienced engineers. Since you are not inexperienced my advice is unlikely to be helpful.

Re: Category Theory for Programmers (2014) [pdf]

#119
post #98
post #92

Earlier quoted context omitted.

Monad transformers are really not the great counterexample you seem to think they are.

Monads were described as uncomposable. Monad transformers are one way they’re composed. I don’t understand your objection.

A lot of people consider Monad transformers as an ugly hack to partially paper of the lack of compositionality of Monads (hence alternative attempts like extensible effects). Something that composes nicely has low overhead, does not introduce additional boilerplate or require making arbitrary additional choices (such as ordering). But Monad transformers do often involve non-trivial overhead, additional boilerplate (not sure how much things have progressed since mtl) and extraneous complexity.

Re: Category Theory for Programmers (2014) [pdf]

#120
post #90

Earlier quoted context omitted.

I've quite literally spent the last month trying to read, digest, and apply the above to a record layer I'm writing for FoundationDB. Dr. Spivak's work has been absolutely beyond helpful and insightful. There's no way I'd even be able to approach the subject with his efforts. I'd also recommend these as they're associated with the 7 Sketches and help fill in some blanks: Functorial Data Migration - https://arxiv.org/…

Since you sound like you're from the category theory community you may already know this, but my database library Opaleye is directly based on David Spivak's ideas. https://hackage.haskell.org/package/opaleye

I'm totally new to the community! So I have no idea about almost anything I didn't link to or isn't linked here, ha.

That is a freakin' awesome link, thank you so much! Though, it'll probably mean yet another rewrite of my record layer :) (at learning is fun)

Post reply on HN