News for hackers. Stuff that matters.
Re:The category design pattern by tyre on Sunday November 08, 2015 @01:18AM (#10527745)
This is wonderful, and correct, theory. As the Futurama joke goes, "you are technically correct; the best kind of correct."

What the Haskell community keeps running into is that most people don't think in theories. Trying to prove the theory to be practical has a poor success rate. They need to implement useful things that people love, then show how the theory got them there naturally.

Sentences like this:

> Category theory codifies this compositional style into a design pattern, the category.

To the average person, a theory codifying a style into a pattern just isn't useful. What does that do? Monads are a common joke to this effect. They are wonderfully useful but poorly understood by most developers. It isn't being right that matters if few understand you.

Why was Rails successful?

Sure Ruby is nice, but Python is very similar (and it wasn't the `do...end` blocks.)

It's because Rails could be used to easily build functional CRUD apps — Whoops! it works — that made difficult easy. Sandy Metz doesn't get heard if DHH isn't building Basecamp.

As a philosopher, it pains me to know people don't think that way, but if you aren't changing people's lives then all the theory is just mental masturbation.

Re:The category design pattern by mbrock on Sunday November 08, 2015 @05:05AM (#10528103)
Haskell isn't designed for "average people" or "most people" and why should it be?

Real human beings use Haskell every day and love it.

Real human beings are capable of learning about teh scary maths and abstract theories.

You studied philosophy? Are you aware that most people don't understand anything about philosophical theories other than The Secret? Have you thought about how maybe those theories can change people's lives even though they're not aimed at a lowest common denominator? E.g. by being influential in the long run, and also by being intellectually stimulating to people who do bother to learn about it?

Rails-style success is not the goal for Haskell. It is an explicit anti-goal: the motto is "avoid success at all costs."

Terse and rude counterpoint to your thesis: Average people are lazy idiots and designing your language to appeal to them will result in a very popular incoherent mess, like Java and Ruby, and Dijkstra will make pointed remarks at you from his grave.

http://www.paulgraham.com/avg.html

Re:The category design pattern by omginternets on Sunday November 08, 2015 @05:59AM (#10528180)
>Haskell isn't designed for "average people" or "most people" and why should it be?

Although it isn't stated as such, I think the point is that the haskell community is, on the whole, truly awful at pedagogy.

I'm perfectly fine with the notion that Haskell isn't for everyone, but being a poor pedagogue is always a bad thing.

Re:The category design pattern by mbrock on Sunday November 08, 2015 @06:08AM (#10528188)
If you're a good pedagogue, please help out.

Teaching isn't easy, and the abundance of poor pedagogy is surely a big reason why so many people develop mathematical anxiety.

https://en.wikipedia.org/wiki/Mathematical_anxiety

> Students often develop mathematical anxiety in schools, often as a result of learning from teachers who are themselves anxious about their mathematical abilities in certain areas. Typical examples of areas where mathematics teachers are often incompetent or semi-competent include fractions, (long) division, algebra, geometry "with proofs", calculus, and topology.

The programming world lately is inundated with tutorials that take their pedagogical style from the Teletubbies or at best Bob Ross. Maybe that is not a viable way of teaching Haskell—maybe there will need to be actual study involved, with textbooks and exercises and trained teachers. I don't really know.

https://www.cs.utexas.edu/~EWD/transcriptions/EWD10xx/EWD103... ("On the Cruelty of Really Teaching Computer Science")

> So, if I look into my foggy crystal ball at the future of computing science education, I overwhelmingly see the depressing picture of "Business as usual". The universities will continue to lack the courage to teach hard science, they will continue to misguide the students, and each next stage of infantilization of the curriculum will be hailed as educational progress.

Re:The category design pattern by omginternets on Sunday November 08, 2015 @06:24AM (#10528210)
>If you're a good pedagogue, please help out.

I truly think I am, but I'm still struggling to learn Haskell...

>the abundance of poor pedagogy is surely a big reason why so many people develop mathematical anxiety.

I'm one of them, but 28 years later, I'm finally realizing that mathematics actually aren't that hard.

>The programming world lately is inundated with tutorials that take their pedagogical style from the Teletubbies or at best Bob Ross. Maybe that is not a viable way of teaching Haskell.

I think you hit the nail on the head, here, and I would like to hazard the following opinion: this is a deeply cultural problem in the United States, where we operate under the implicit belief that learning should be fun.

I don't mean to suggest that learning isn't rewarding, deeply satisfying, and occasionally exhilarating, but beyond learning your ABCs, it's rarely fun in the traditional sense. The problem, as I see it, is that we're failing tell the truth: learning non-trivial things is tedious, grueling, difficult, and tooth-grindingly frustrating while still being one of the most worthwhile things in life. Instead, we try to teach difficult or non-obvious concepts with the pedagogical equivalent of coloring books.

Stated differently, we simultaneously tell our youth that one has to "work hard" and "make sacrifices" for things like sports, while telling them that intellectual pursuits should be nothing less than blissfully entertaining.

As a general rule, I avoid anything labeled as being "for beginners", unless it's from a foreign editor. I'm lucky to be a fluent speaker of French, and I've noticed that French textbooks systematically approach subject matters in a rigorous, Cartesian, matter-of-fact way ... and this from grade 1!

You want to know how I finally grokked monads? I read this paper: http://repository.cmu.edu/cgi/viewcontent.cgi?article=2846&c...

It sucked. I mean it was awful. I spent weeks pouring over this thing, fighting the kind of frustration I described above.

And I got a D+ in undegraduate pre-calculus. I'm not a "math guy", but like everybody else, coloring books don't cut it after you start growing armpit hair. Big-boy concepts require big-boy methods.

Re:The category design pattern by mbrock on Sunday November 08, 2015 @06:44AM (#10528249)
Agreed, and thanks, that looks like an interesting paper.

In Gothenburg, Sweden, where I studied, Haskell is the first introductory language for students of CS and (I believe) CE. I know people who had barely even used a computer when they started there who are quite proficient with Haskell.

A side benefit of that is that the dorks like me who had been coding Perl and C and whatever for years before were thrown back to "oh shit, I have to actually study" mode and thus equalized with the people who were starting from scratch.

In terms of gender, when I started studying women were way less likely to have been coding since the age of 6. In the exam for a later course on Advanced Functional Programming that included monad transformers, functional embedded languages, the basics of dependently typed programming, and a semi-large Haskell programming project, I was happy to see a female classmate who hadn't programmed at all before university get the best score of anyone. But I digress... (Shoutout to Elin if you're reading!)

I'm somewhat anxious that my way of talking about this stuff might make people think that Haskell is way more difficult to learn than other languages, which I don't think is the case. I think people probably forget how much trouble they had grokking concepts like "objects" and "superclasses" and "generators" and so on. Haskell might be difficult in some other ways. Maybe in some ways it forces you to really understand things more than other languages. But it's still very possible to learn to program in Haskell without being exceptionally good at math.

Also, some of what people find tricky about Haskell is also present in other ML-style languages. I learned about O'Caml and some SML, and also Scheme, before I got into Haskell. So I knew about functional recursive styles of programming, and algebraic data types, and probably the biggest new things were lazy evaluation and the complete lack of side effects leading to the need for monadic sequencing. Those are not insurmountable.

Edit: By the way, I also appreciate how Haskell is becoming a sort of grass roots study group for coders to learn more about math, algebra, category theory, and what have you. It is not at all constrained to the universities anymore. This article is at the top of HN right now! Interesting times.

Re:The category design pattern by jacquesm on Sunday November 08, 2015 @08:00AM (#10528361)
I think you're on to something here. It may be that programming languages that require you to 'reboot' are better suited to people totally new to programming than to people that already know how to program using some other methodology.

This is because compared to your old, well used and worn tools that new tool starts off as a set-back rather than an advantage and we more or less expect an instant productivity boost from new technology. That set-back then becomes a huge hurdle to overcome.

The question a programmer faced with a problem to solve is always one of investment: should I invest my time and effort into this new technology that will make me x times more productive or simply a better programmer (or someone capable of tackling more complex problems) a year or more down the line, or should I break out my trusty tools and turn a buck today (or turn a buck for my employer).

In most cases that equation works out in favor of the old tools so the energy required would need to be offset by concrete short term gains if a person is to switch from one tech to another.

That lack of concrete short-term gains is the big stumbling block for old hands, and if you manage to hack that then I think a lot of these better technologies would find traction.

People new to programming don't have that particular hang-up and I'd expect them to do much better with such new tool or different tools. (But they'd have the same problem if they needed to switch to other tools, it's just that in this particular instance they have a blank slate advantage, that evaporates the moment they become proficient in that technology.)

Re:The category design pattern by jib on Sunday November 08, 2015 @12:42PM (#10529141)
I went to the same school (I presume) in Gothenburg. I came into the CS classes with a decent amount of math background, and a small amount of programming classes (FORTRAN, C, ADA and other kinds of evil you use in chemistry and physics). Our CS intro classes were Java and Haskell. Haskell didn't feel like a reboot to me, it felt like using math to write programs, so at least for me, Haskell felt a lot more accessible than learning OO concepts in Java did. I am sure lecturers caring more about Haskell also mattered, but at least for my background, getting the Haskell concepts was a easier than the Java concepts.
Re:The category design pattern by jwdunne on Sunday November 08, 2015 @10:16AM (#10528679)
This comment and the parent comment was really interesting. It's made me think about my current path and somethings I have done/learned that has incrementally pushed me towards functional programming over a long window of time.

I have played with Scheme, along with a half-completed SICP read through. I have also played with Haskell, along with partial read throughs of LYAH and real-world Haskell. Those experiences, although incomplete, have been important to me as a programmer. I don't think those actually 'sold' me on FP though.

I took a detour for some time and decided to become a better programmer using OO methodologies. I used TDD, I memorised SOLID and all that. Read up on design patterns and then used them practically. All well and good. From my toying with Scheme, Haskell and associated literature, I wasn't entirely satisfied. The code I produced was always a bit, I'm not sure, but not entirely satisfiying. It looked and worked better than what I get given to review when considering freelancers for an extra pair of hands - part of that is because of PHP I think. I carried on this way for a while in any case.

In my own self-learning, I'd started looking at language design and compilers. I read some books and decided I didn't have enough mathematical skills to consume the texts. I turned to learning discrete mathematics. That was a big eye opener. As I was reading about formal logic, set theory, proofs, etc, my mind kept turning to the problem of applying this in my work. Haskell and FP came to mind too. I believe doing this helped it finally click that a functional approach can be taken successfully in most of the work I do.

Whilst I was doing this, I had a fairly simple project that, if designed correctly, could make my life easier in future projects. I took an OO approach, designed the UML, started writing tests, etc. I decided that it was over-engineered or at least it was a lot of work for what I was trying to do. I decided to take an FP approach. I had the project completed with far less code that I was happier with. In the same language. That was almost like an 'epiphany moment'. I started getting seriously interested about functional programming then. I am now starting to see the flaws and bloat in the approaches I was taking before.

I recently read Out of the Tar Pit again. I had read it before but I didn't really get it. This time it excites me and made my brain whir with ideas. Especially on how I can make these approaches compatible with the constraints of my day job.

I actually now digest as much as I can about FP. Haskell, as an important player, frequently comes up. After laying the ground work, monads make a lot more sense. Haskell as a language excites me.

In my opinion, and I am self-taught when it comes to computers so it may not be 100% applicable, here is what I did to start my transition from imperative to declarative:

a) experiment with functional programming. Not actually get it and be ok with that. Carry on down the path.

b) Read HN and note articles posted about FP

c) Continue learning about imperative programming and consume the advice from OO thought leaders. Apply it to your work.

d) Learn a bit about maths and what it actually is, especially realising it's not just rote computation and application of algorithms from school.

e) Take a functional approach instead of an OO approach within the language you are working with. I did this in PHP. Not only will it show you how FP compares, it will also show you why Haskell/OCaml/etc by way of the deficiencies for FP in your chosen languages. In PHP, the type system (arrays as your Everyman...) and inconsistent type hints, explicit closing over of variables in outer scopes and piss-poor support for modules is one. Biggest is the only way to pass a function in the function namespace is to use a a fully-qualifies string (so function name along with namespace - you get undefined constant otherwise). With Java, it might be that you cannot have stand alone functions, which would suck.

This helped a lot for me but I'm sure spending a long time learning about software down to the hardware in my spare time contributed a lot to this too.

Re:The category design pattern by mbrock on Sunday November 08, 2015 @10:59AM (#10528811)
Nice to hear.

I had similar moments of epiphany while taking a course on abstract algebra and writing down some theorems in the form of Agda definitions.

As you may know, Agda is a Haskell-inspired language that has an even more powerful type system that makes it possible to define arbitrarily strong types, so that for instance you can define the type of a function that sorts a list—and then know confidently that any implementation of that type does indeed sort a list.

Anyway, when learning Agda, one comes across the notion that programs and proofs are in some sense the same thing. In other words that the code for a function can be read as a proof that the type of that function is inhabited. This seemed to me kind of bizarre and magical at first...

The more I thought about it, the more it made real sense, and not only that, it helped me understand proofs in a much more intuitive way. Before, if you had asked me what a proof is, I might have said "it's a very strict way to argue that a statement really is true." I didn't know that such proofs can be given formal structure... I couldn't really explain how to relate it to programming or functions...

But now that I've to some degree internalized the notion, if you ask me what a proof is, I might say it's an unambiguous description of how to transform an input into an output.

If you call the input P and the output Q, then P is a premise and Q is a conclusion, and the proof is the "arrow" P -> Q that through some well-defined sequence of "truth-preserving transformations" gives you knowledge of Q assuming nothing but P (and some fundamental axioms).

And in the world of programming, P is an input argument and Q is a resulting value, while the "arrow" P -> Q is a well-defined sequence of correct transformation that produces a Q-value given only a P-value (and some fundamental primitive functions).

So in this sense you can say that the implementation of a function is actually a kind of logical argument.

If you want to make use of this insightful connection (the "Curry-Howard equivalence"), however, your programming language needs to be pretty strict. If your P -> Q argument suddenly throws a null pointer exception, it's not much of an argument—it means your claim of being able to produce a Q given P is false.

This connection really helped me to understand both proofs and programs in a deeper way.

Re:The category design pattern by jwdunne on Monday November 09, 2015 @04:16AM (#10532044)
Thank you.

1. I'd heard of Agda but never read any code. What a brilliant language. I've added it to my list of my languages to spend time with.

2. I think your experience with Agda, especially the realisation that programs = proofs, leading to the Curry-Howard correspondence is exciting and rightfully bumps Agda to the top of my list.

Functional programming has also opened my eyes with type systems too. That actually, an inconsistent and weak type system is a bigger liability than once thought - I'm realising that daily. Especially with null values and "trying to call method on non-object" errors.

Re:The category design pattern by spion on Sunday November 08, 2015 @03:12PM (#10529675)
If you could share some of the resources you used to explore discrete mathematics, that would be really helpful.
Re:The category design pattern by jwdunne on Monday November 09, 2015 @03:10AM (#10531851)
I found the book 'Discrete Mathematics and It's Applications' a helpful book. People often recommend 'Concrete Mathematics' too.
Re:The category design pattern by mbrock on Sunday November 08, 2015 @08:32AM (#10528435)
Excellent quotation in the intro to that paper:

> ... Our intention is not to use any deep theorems of category theory, but merely to employ the basic concepts of this field as organizing principles. This might appear as a desire to be concise at the expense of being esoteric. But in designing a programming language, the central problem is to organize a variety of concepts in a way which exhibits uniformity and generality. Substantial leverage can be gained in attacking this problem if these concepts are defined concisely within a framework which has already proven its ability to impose uniformity and generality upon a wide variety of mathematics.

(John Reynolds, "Using category theory to design implicit conversions and generic operators", 1980.)

Re:The category design pattern by omginternets on Sunday November 08, 2015 @08:47AM (#10528459)
I'm truly glad that you're enjoying that paper :)

This is completely unrelated, but I found this paper to be similarly brilliant in its simplicity, clarity, and rigorous explanation: https://ramcloud.stanford.edu/raft.pdf

Re:The category design pattern by zeckalpha on Sunday November 08, 2015 @09:06AM (#10528501)
That paper took 25 years to refine. Additionally, for the right audience, more math could make it more succinct.
Re:The category design pattern by omginternets on Sunday November 08, 2015 @09:29AM (#10528556)
I don't doubt it, but I'm not sure what you're trying to say. Would you elaborate?
Re:The category design pattern by catnaroek on Sunday November 08, 2015 @03:41PM (#10529799)
I have a hard time already convincing myself that correct sequential imperative algorithms are indeed correct - which probably means that I'm a bad programmer, but I can't change who I am. So convincing myself that that Raft, a concurrent algorithm, is correct (meets its specification) from an informal description is completely out of question - where is the formal proof of correctness?
Re:The category design pattern by mbrock on Sunday November 08, 2015 @04:49PM (#10530122)
Take a look here for pointers to formal proofs:

https://news.ycombinator.com/item?id=10017549

Specifically Verdi, a Coq framework for distributed system verification, which now includes a formally proven Raft implementation.

https://github.com/uwplse/verdi

This appears to be the main theorem, "raft_linearizable":

https://github.com/uwplse/verdi/blob/master/raft-proofs/EndT...

Re:The category design pattern by catnaroek on Sunday November 08, 2015 @05:24PM (#10530252)
Thank you very much. :-)
Re:The category design pattern by omginternets on Tuesday November 17, 2015 @03:50PM (#10583851)
Ah, sorry. I think you're reading this with a much deeper understanding of mathematics than I.

I'm really curious, though. Could you give me some insight into how algorithms are proven correct?

Re:The category design pattern by jacquesm on Sunday November 08, 2015 @07:52AM (#10528347)
The most dreaded words in math education: 'from which it is obvious that...'.
Re:The category design pattern by marchdown on Sunday November 08, 2015 @10:40AM (#10528753)
What are some examples of good pedagogy in programming?

I would point to pretty much anything by Norvig, Knuth, Sedgewick, and maybe to Zed Shaw's agressive tutorials.

Re:The category design pattern by sageikosa on Sunday November 08, 2015 @07:56AM (#10528353)
Pedagogy is related to teaching children, andragogy is the education of adults. Each has unique challenges in that the young lack a base of knowledge and adults may have their own conceptual frameworks that need to be addressed.
Re:The category design pattern by omginternets on Sunday November 08, 2015 @08:06AM (#10528376)
Semantics! (Though I'll be sure to remember that distinction for future conversations).
Re:The category design pattern by sageikosa on Sunday November 08, 2015 @12:48PM (#10529163)
Fair enough. Teaching non-developers functional programming may prove an entirely different challenge than teaching procedural programmers functional programming.
Re:The category design pattern by tome on Sunday November 08, 2015 @08:07AM (#10528380)
This seems to disagree with standard usage: https://en.wikipedia.org/wiki/Pedagogy
Re:The category design pattern by throwawayignt on Sunday November 08, 2015 @09:09AM (#10528504)
If you ever see anything online that has more than, say, half a dozen users, then it is NEVER the case that it suffers from "poor pedagogy". Why? Because it only takes 1 person to explain something, even if it's brief, people will start linking to there and eventually that method of explanation spreads. Like pointers in C, or classes - who would say they "suffer from poor pedagogy"? Anything is easy to teach, it just takes a single person who undersatnds it.

But.

If you ever see a technology truly suffer from "poor pedagogy" then it has a secret: in some fundamental, underlying way, it sucks.

Now the rules of the game are different. Suddenly, those who understand it will keep it under their breath and muddy the issue. No one will be explicit about these design choices and simply explain it: to explain it is to criticize it.

Then you have this case where people are holding their tongue, and those who eventually figure something out join that small cabal and simply don't mention it in normal, sane terms. They just don't - it would be rude to do so.

So remember. If you ever perceive poor pedagogy online in any tech subject, then it is camouflage, you are being lied to. In some fundamental way nobody will mention, it simply sucks.

At that point it's up to you to read between the lines and decide whether it still has enough benefits for you to learn it.

Re:The category design pattern by mbrock on Sunday November 08, 2015 @09:33AM (#10528565)
If you can explain clearly why something "sucks," then that explanation will spread and soon enough everyone will agree that you are right and the thing is useless and bad.

But if you notice yourself spreading irrational FUD under throwaway nicknames, and people don't seem to quickly catch onto your point, it may be that secretly and fundamentally, you are trolling.

Re:The category design pattern by throwawayignt on Sunday November 08, 2015 @09:56AM (#10528618)
it's inappropriate to make ad hominem attacks here, please refrain from doing so.

I didn't name any shortcomings in Haskell, I gave a general rule of thumb.

However, as you yourself demonstrate dramatically, by using an ad hominem and saying "spreading irational FUD", if I did have a clear and rational understanding of why your prefered technology has underlying shortcomings as a trade-off, which learners need to deal with, then I certainly would keep that information to myself. Who wants to be skewered by a community?

For this reason, you will never see clear explanations in that format. Instead, people who have attained that information for themselves will simply keep it to themselves - they won't teach it at all. They will teach it without reference to alternatives or to the strength of trade-offs that have been made.

That's why it will seem like a case of "poor pedagogy". But it never is that. It's a case of people in the know politely avoiding teaching it.

Please note that this is just my personal opinion, you can disagree with it. I didn't mean to start a debate.

Re:The category design pattern by mbrock on Sunday November 08, 2015 @10:42AM (#10528760)
You were claiming, with extremely vague reasoning from a throwaway account, that any technology with a reputation of bad pedagogy—obviously referring to Haskell—"fundamentally sucks."

Ad hominem fallacy is when you use a character attack but pretend it is a logical argument. I don't claim to make a logical argument—there's nothing logical in your comment to respond to.

If you don't want to start debates on the internet, try not telling people that the technology of their choice "fundamentally sucks."

Re:The category design pattern by throwawayignt on Sunday November 08, 2015 @10:58AM (#10528808)
Haskell doesn't have a reputation of bad pedagogy per se. My only point was what anyone's reaction should be when their personal impression is "bad pedagogy", in any area of software. It means that something is missing.

The idea that I'm "obviously referring to Haskell" and attacking me for it is beneath a response.

By the way this thread is an excellent example of why if I did have clear arguments for limitations baked into technology xyz, I certainly wouldn't share them: leaving learners in the difficult position of being presented difficul material/approaches, without a context, by those who understand it but keep mum about any limitations or difficulties.

(An example would be the syntax for standard library container operations in C++ (stl things), like with vectors. Nobody is going to explain that this syntax is so much uglier than higher-level vector/array syntax due to history, because the minute they did it would become obvious that there should be a CoffeeScript-like intermediate syntax parser that turns easy syntax into C++. Instead, it's presented without any such context, and nobody fixed the fact that this is harder to learn, harder to parse or debug, and more error-prone, than higher-level interpreted languages. It's just silently accepted without reference to this being a historical design trade-off.

I'm not objecting to it, but if something seems to be described circuitously or not being taught very well, then you're probably not being told the whole story.

There is a good and specific rason why.)

Re:The category design pattern by mbrock on Sunday November 08, 2015 @11:15AM (#10528855)
I apologize for misinterpreting.

Note that just as your original comment was murky and seemingly accusatory, so was my original reply to you—because I was parodying you.

You talked about unspecified things fundamentally and secretly sucking... so I said that you might be fundamentally and secretly trolling... who knows if any of these claims are true? They're both murky, vague, and somewhat paranoid.

The more straightforward argument you're producing now seems interesting, and I agree to some extent. I'll happily admit that Haskell—just like every single language—has historical warts and problems. Some of them are being addressed by the community, with some of them the community is stuck in arguing, etc.

C++ has always been firmly committed to backwards compatibility, which is one reason it is such a successful industrial language. Haskell has some of that too, and incompatible changes made to the core language are rare and always met with suspicion.

However, I don't think the Haskell community is especially dogmatic about the perfection of their own language. If anything, people are constantly discussing ways to make it better.

Re:The category design pattern by tome on Sunday November 08, 2015 @11:15AM (#10528857)
> The idea that I'm "obviously referring to Haskell" and attacking me for it is beneath a response.

You were replying directly to a post that claimed "the haskell community is, on the whole, truly awful at pedagogy" so it's easy to see how mbrock mistakenly concluded that, when you said "in some fundamental, underlying way, it sucks", you were referring to Haskell (when in fact you meant something entirely different).

Re:The category design pattern by omginternets on Sunday November 08, 2015 @10:03AM (#10528637)
His point is that your argument is so difficult to follow that it looks ad hoc. That, in combination with your throwaway account, raises red flags for trolling.

Ad hominem attacks are informal fallacies, granted, but they're still sometimes relevant.

Re:The category design pattern by omginternets on Sunday November 08, 2015 @09:38AM (#10528574)
So difficult concepts are useless... got it.

>Anything is easy to teach, it just takes a single person who undersatnds it.

Spoken like someone who's never taught a difficult subject.

More to the point: this is what anti-intellectualism looks like, and it's not something to be proud of. If you made the effort to understand the occasional cryptic idea, you'd be amazed at the number of useful things you would learn.

Re:The category design pattern by throwawayignt on Sunday November 08, 2015 @10:03AM (#10528639)
I'm sorry, can you give a single example in the arts and sciences of something that has a reputation for "poor pedagogy"? (But is in fact just inherently difficult.)

Here are some inherently difficult subjects: quantum field theory, advanced calculus, orbital mechanics. Do any of these subjects suffer from a reputation of "poor pedagogy"?

I was referring instead to specific technological solutions, and, specifically, to encountering the idea that a subject "merely" suffers from poor pedagogy.

My comment had zero to do with the difficulty of any subject.

Re:The category design pattern by raverbashing on Sunday November 08, 2015 @10:11AM (#10528665)
> Average people are lazy idiots and designing your language to appeal to them will result in a very popular incoherent mess, like Java and Ruby, and Dijkstra will make pointed remarks at you from his grave.

This is so funny

Yeah, Ruby and Java are not great. But they get the job done and produce value, and a lot of people use it.

I couldn't care less what Dijkstra thinks, he's not the one paying my bills

If you can see the value in Haskell great. But I find it hard to remember where are the big technology companies using Haskell (or tools built with it). Maybe because if you force 'mathematical consistency' in an inconsistent world everything else sucks

Re:The category design pattern by mbrock on Sunday November 08, 2015 @10:31AM (#10528718)
Sure. I'm a huge fan of bash scripts but I'm certain that attempting to enforce mathematical consistency on that language would be a comical disaster. (Although Gabriel Gonzales's "pipes" library for Haskell does make reference to a categorical interpretation of Unix pipes—hey, it's like this "math" stuff is quite widely applicable.)

Look up Facebook's use of Haskell if you're curious about industry use.

https://code.facebook.com/posts/302060973291128/open-sourcin...

I worked for a startup that used Haskell for its entire backend, including a custom kind of graph database. I joined my coworkers to a Haskell hackathon in Zürich and met hundreds of people using the language commercially (and happily).

It's not that Java and Ruby suck—it's just that they're incoherent and messy. That may sound like slander but I have used both languages professionally, I have contributed to both Rails and the Ruby interpreter, I don't think they are bad tools. Everything is a tradeoff. If you CAN'T see the value in Haskell, I humbly recommend you look into it, but I can't force you to become interested.

Re:The category design pattern by Numberwang on Sunday November 08, 2015 @05:45AM (#10528158)
So the goal is for Haskell to be the Ithkuil of the programming world?

That's a noble idea. Knowing this also makes it easier for me to chose to avoid reading articles about it.

Re:The category design pattern by mbrock on Sunday November 08, 2015 @05:49AM (#10528167)
No. The goal is to be useful in both research and industry by means of principled design based on mathematics and engineering. If that scares you, fine, you don't have to be interested in everything. If you think everything that's not designed to appeal to some notion of an "average programmer" is necessarily obfuscated and impossibly difficult, that's on you. Go ahead and avoid it.
Re:The category design pattern by Numberwang on Sunday November 08, 2015 @06:22AM (#10528204)
That sure does sound like a yes, not a no.
Re:The category design pattern by stingraycharles on Sunday November 08, 2015 @07:52AM (#10528348)
No it is not. Haskell appeals to a certain audience, for the same reason that assembly and C/C++ appeal to a certain audience (fun fact: this category pattern will also be available in C++17 to be known as Concepts).

Sure, it is a niche language, and might have too steep a learning curve for the average programmer, but it is used in production, by real world businesses, and people write real world code with it.

Re:The category design pattern by T-R on Sunday November 08, 2015 @03:28AM (#10527947)
The theory is for getting consistent/composable APIs, and trust in the code - trust that you can optimize it, parallelize it, or just that it behaves the way it's supposed to, without having to read every line of it. You don't need to think in theory to benefit from that.

While it's certainly cute that I can `gem install` a CMS, the Ruby ecosystem is infamous for its magical, non-composable, monolithic frameworks. The functional ecosystems are working toward fixing the all-too-familiar problem where you have to either start over, or hack apart some giant stateful mess anytime your exact usecase hasn't already been built as a library. It's easy to throw a nice looking house together with Lincoln Logs, but I'd take Lego instead any day.

Edit: Also, just because someone hasn't built the tallest building in your neighborhood yet doesn't mean they're not building anything. JP Morgan, Kapersky, Facebook, and IMVU are hiring Haskell devs, just off the top of my head.

Re:The category design pattern by virtualwhys on Sunday November 08, 2015 @07:02AM (#10528276)
Agreed on popularity of language/framework not being an indicator of success (wrt to software evolution), quite the opposite seems to happen in the mainstream.

Worth noting that finance industry heavyweights such as JP Morgan and Standard Chartered (largest Haskell shop in the world) are laying off more than they're hiring these days[0][1], though unlikely this trend would directly affect tech hires (current batch of layoffs seem to be a trimming of management tier).

On a somewhat related note: were Standard Chartered to open source their fork of GHC many Haskellers not sold on lazy-by-default would rejoice; from Scala side of the fence my interest in Haskell would increase 10X were that to happen, line numbered stack traces alone, who woulda "thunk" it ;-)

Moving forward Haskell's probably going to continue to be pilfered of its theoretical gems by other languages that leap frog it in terms of adoption. Not a bad thing if we take SPJ's "avoid success at all costs" at face value.

[0] http://www.bloomberg.com/news/articles/2015-05-28/jpmorgan-s...

[1] http://www.bloomberg.com/news/articles/2015-07-20/standard-c...

Re:The category design pattern by T-R on Sunday November 08, 2015 @01:06PM (#10529220)
Sure, we can have a perfectly reasonable debate as to whether or not lazy-by-default is the best choice for a language. I personally like the laziness, but if Scala, or Closure, or ML, or Elm, or maybe by some act of god COBOL "wins" by taking the good parts, that's fine.

But here, we have an article trying to make some concept approachable - some math, not tied to a specific language. Maybe it's hard for most to follow, since it assumes the readers knows what a monad is. That's fair, but it'd be the same if it were Scala.

The top comment here - and a significant number of the upvoted comments here, and on every similar article - are just baseless attacks against the idea that people should learn this. Not questions or technical discussion, just attempts to ostracize the part of the community that finds it valuable. It's anti-intellectualism, plain and simple. Maybe it's the terminology, or the syntax, or because articles didn't show the lock before giving the key, but it is what it is.

- Re: Hiring - JP Morgan may be doing layoffs somewhere, but I mentioned them because they made a "Hiring Haskell Devs" post within the last week.

Edit: Seriously, go re-read that top comment, from the condescending reference down to the assertion that it's all mental masturbation. In response to a post by a knowledgeable person trying to teach something useful to people who are interested. That's the top comment. Embarrassing.

Re:The category design pattern by wetmore on Sunday November 08, 2015 @08:10PM (#10530879)
>That's the top comment. Embarrassing.

My experience on HN has been that the top comment in most threads is usually the most incendiary one, not the "best" one.

Re:The category design pattern by tome on Sunday November 08, 2015 @07:09AM (#10528284)
> Worth noting that finance industry heavyweights such as JP Morgan and Standard Chartered (largest Haskell shop in the world) are laying off more than they're hiring these days[0][1], though unlikely this trend would directly affect tech hires (current batch of layoffs seem to be a trimming of management tier).

Indeed. Hiring of Haskellers continues apace at SC: https://twitter.com/donsbot/status/654630194519646208

> were Standard Chartered to open source their fork of GHC many Haskellers not sold on lazy-by-default would rejoice

It's not a fork of GHC. It's an entirely new compiler, called Mu.

Re:The category design pattern by dons on Sunday November 08, 2015 @09:13AM (#10528513)
Yes, the tech is eating the rest of the business. You need less people after you've turned a lot of the business into an API.

I've got four open positions at the moment.

Re:The category design pattern by 15155 on Sunday November 08, 2015 @07:01PM (#10530647)
JP Morgan may be laying people off but they had a hiring ad out on the Haskell subreddit <1 week ago [1] looking for help.

I don't think general layoffs at all correlate to language usage in this case (they didn't cut a Haskell team, specifically).

[1] https://www.reddit.com/r/haskell/comments/3re0kp/jpmorgan_ha...

Re:The category design pattern by huuu on Sunday November 08, 2015 @03:03AM (#10527910)
Some time ago there was a post about this (I can't find it).

People don't understand what monads are because they don't know what problem they solve.

This article has the same problem. It doesn't explain what problem categories solve. Well it does but the average reader doesn't understand the problem exists.

Re:The category design pattern by mbrock on Sunday November 08, 2015 @05:46AM (#10528161)
I think they also don't understand monads because they have confused notions about the kind of concept "monad" is on the meta level. Their criteria for understanding and their methods of learning are unsuitable for becoming competent with the use of algebraic concepts. They are trying to think their way to a type of "intuition" that simply is not possible, kind of like trying to learn to ride a bike by "understanding" bikes, comparing bikes to various other things, or spamming the internet with complaints about how bikes are strange and difficult. (What's the problem with just taking the bus?!)

If Haskell's "Monad" type class were instead called "AbstractComputationFactory" or some other such intimidating technobabble, then when someone looks up what is the superclass of IO they might just think "oh, that's some weird detail, whatever, I might learn about that later." Since instead the name "Monad" is vaguely funny and appealing, people want to master that concept in principle before they even get "Hello, world!" to run in GHCi.

Of course people are free to focus on whatever they want, and we can talk about the possibility of improving the pedagogical aspects of Haskell, and probably university teachers have interesting things to say about that.

But there is no magic way to explain an algebraic concept that will suddenly make it intuitive and easy. If people want to understand them, they'll have to study. If people want to use them without understanding them on the conceptual level, that is eminently possible.

I myself don't understand monads and I've been using Haskell since 2005. I'm just not good at abstract algebra (flunked that class) and PDFs terrify me. However, even though if a mathematician asked me to explain monads I would be embarrassed, I can still use them and even define my own. That's because I've tinkered with them and acquired a know-how feel for the structure and what they are good for and how the patterns work—which is exactly how I've learned every other concept in programming.

Since most concepts in programming are ad-hoc, informal, and specified by hand waving, there is not even a possibility of understanding them at the level of mathematical rigor. What is an object? What is a class? Nobody knows. They just use them.

Re:The category design pattern by icebraining on Sunday November 08, 2015 @08:15AM (#10528401)
More than people trying to learn Monads, I see people trying to teach them. Few people write introductory guides to the "AbstractComputationFactories" of other languages, but it seems like everyone who gets (or thinks they get) monads feels the need to write a guide on them. It's inevitable that newcomers to the language will stumble upon them early on.
Re:The category design pattern by mbrock on Sunday November 08, 2015 @08:27AM (#10528423)
True enough. That has to do with the allure of jargon, I think. It's become a meme in itself. Nowadays on the Haskell subreddit, what I see most upvoted are tutorials that involve creating software that does something concrete. If that happens to involve a clever but not overwrought use of cool type system features, all the better. If anyone reading is yearning for some internet points, go write a Haskell tutorial that's useful, concise, and mostly shies away from the rabbit hole of abstract explanations. Even if it's merely about how to run a regexp or do a POST request.
Re:The category design pattern by agumonkey on Sunday November 08, 2015 @03:39AM (#10527971)
It's like explaining Iterable interface out of the blue.
Re:The category design pattern by userbinator on Sunday November 08, 2015 @10:13AM (#10528669)
People don't understand what monads are because they don't know what problem they solve.

Or for that matter, the fact that it even is a problem, because it's easy to see that there are plenty of other programming languages with which people can do lots of productive things without ever thinking of the term "monad".

Re:The category design pattern by david_ar on Sunday November 08, 2015 @06:25AM (#10528212)
Replace the word "theory" with "abstraction" or "interface" then. All the article is saying is that there's a bunch of common things (Unix pipes, function composition, procedure sequencing) that all follow a few simple rules (a "contract" if you like). This means you can reason about them together without having to think about the individual "implementation details".
Re:The category design pattern by cristianpascu on Sunday November 08, 2015 @03:20AM (#10527929)
Reading this article I had the same feeling I had when I was a physics student in math classes: Why the haskel do I need this? Like every time some abstract math concepts were introduced with no connection to reality whatsoever.
Re:The category design pattern by bordercases on Sunday November 08, 2015 @03:26AM (#10527936)
For me, learning mathematics is a way of priming my imagination with patterns and tools that may or may not be relevant, but with the qualification that almost everything can find use if you look hard enough. I'm curious and like to think so having a library of abstractions is always satisfying. Just sitting down to figure out how math can apply to some simple object of meditation is usually fruitful.

You can get away speaking English with a relatively compact vocabulary. But reading broadly to enrich your vocabulary with new words and idioms allows you to describe events more fluidly, and perhaps in a way which inspires you into better ways of describing the same thing you could have described less poetry in the compact vocab set. In that way words let you change your perspective by affecting how you frame your sense-data.

Mathematics is the same way. If you want to work in a variety of domains, you're going to have to be agnostic ahead of time as to what tools might be useful, which is to say, have many tools.

Re:The category design pattern by seanmcdirmid on Sunday November 08, 2015 @05:06AM (#10528106)
You don't learn an English vocabulary by reading the dictionary, you read literature and see how those words are used in context.

Learning in a vacuum is hard for all but the most abstract thinkers.

Re:The category design pattern by johncolanduoni on Sunday November 08, 2015 @06:23AM (#10528206)
I don't think I've ever read a math book that just went "Here is a list of definitions and the statement of some theorems. Have fun!" The problem is that math is usually built on top of more math. So the motivating examples given are often examples in mathematics, just in a different area.

For example, most category theory books talk a lot about the categories of abstract algebraic structures to get you an idea of what the things they're describing look like in "the wild." If you've never done any abstract algebra, it's like trying to use the Rosetta stone when you don't know Egyptian or Greek.

Re:The category design pattern by porker on Sunday November 08, 2015 @07:21AM (#10528301)
> Just sitting down to figure out how math can apply to some simple object of meditation is usually fruitful.

I personally find that bordering on impossible (and I still obtained a physics degree). I need a few examples of how a concept can be applied before it starts making sense.

At the moment I'm dabbling in image processing, and it wasn't until I had some visual explanations of morphology that it made a bit of sense. Now the maths has to follow on...

Re:The category design pattern by Retra on Sunday November 08, 2015 @12:03PM (#10528985)
As a physics student in math classes, you should be more aware of the applicability of abstract theories, not less.
Re:The category design pattern by fsloth on Sunday November 08, 2015 @03:26AM (#10527935)
I terms of usability this seems to me up there with the set theoretic formulation of relational model. I.e. not as something everybody needs to do but offering an efficient descriptive model for complex systems.

When designing programs or datastructures I prefer to use pen and paper and some simple set theoretic ad hoc notation system.

I write code for production daily and without this higher level design model my code would be uk terrible shape and very slow to modify.

"As a philosopher, it pains me to know people don't think that way, but if you aren't changing people's lives then all the theory is just mental masturbation."

Basically really good programmers seem to see the optimal structure for a specific problem out of practice. I need to have some sort of theoretic framework which to use to compose my program logic.

I've not had the time to look into category theory but this post succeeded in convincing me it's a practical mental tool to help in program composition.

So, based on my personal preferences, I disagree this would not have practical benefits.

Re:The category design pattern by smadge on Sunday November 08, 2015 @03:22AM (#10527932)
> To the average person, a theory codifying a style into a pattern just isn't useful

I think the average OO programmer recognizes the value of design patterns, eg the Gang of Four book.

Re:The category design pattern by danieldk on Sunday November 08, 2015 @03:30AM (#10527950)
Only after realising what 'problem' a pattern solves, perhaps by experiencing the problem over and over. I think this is why design patterns in OO are commonly abused (overused) - people learn about them without understanding the problem.
Re:The category design pattern by smadge on Sunday November 08, 2015 @03:38AM (#10527970)
Sure, I agree. Novice programmers are not going to instantly understand what a category is, or how to utilize compositional programming without a bunch of experience and examples. However, I think for programming to progress we need to develop theory.
Re:The category design pattern by Swizec on Sunday November 08, 2015 @03:50AM (#10527991)
The proof is in the pudding.

You know why we have JavaScript? Because someone went and built it. Once it was built, it existed and people used it. All the theories about what a scripting language for the web should look like fell out the window the moment someone went and put one in their browser.

De facto standards beat de jure standards. Every time.

Theory is great. It makes for amazing and stimulating conversation. But in the real world the only thing that counts is building shit.

PS: this is also why English is the global language of trade and not Esperanto. Even though English is both harder to learn, has a terrible "API", and inconsistent semantics and grammar and syntax. Esperanto is clean and well designed and and learnable in 150 hours and not used by anyone.

Re:The category design pattern by tome on Sunday November 08, 2015 @04:33AM (#10528063)
> De facto standards beat de jure standards. Every time.

Only for a very base definition of "beat". People are falling over themselves to write X-to-Javascript compilers because Javascript simply isn't good enough.

Re:The category design pattern by smadge on Sunday November 08, 2015 @04:15AM (#10528028)
Well, presumably an advance will eventually provide a competitive advantage.

For example, before the Copernican revolution, we had a model for the cosmos that made decent predictions. The heliocentric model actually made worse predictions for a long time until it was evolutionary improved. However, to the early scientists who adopted it, the heliocentric model "felt right."

Maybe right now programming in a shitty language like javascript with no regard to program structure is better at "getting shit done" than programming in a functional language using universal abstractions like composition. To people who study and think about it, though, it "feels right." Perhaps if they stick with it and perfect the art, it will eventually provide such a competitive advantage that it will be universally adopted.

Re:The category design pattern by Swizec on Sunday November 08, 2015 @10:23AM (#10528695)
There are already JS libraries for things like functional composition. If current trends persist, it will eventually get language-level support for that.

JavaScript is a tricky language like that. It lurks in dark alleys, beats up other languages and rifles through their pockets for spare syntax and semantics. Much like English.

Re:The category design pattern by fsloth on Sunday November 08, 2015 @03:30AM (#10527952)
Yeah, but the GoF book mostly is gobbledygook when designing program composition - it mainly shows how to patch java and C++ to be more like scheme. It does not actually help that much in program composition.

To quote Feynman incorrectly, Design patterns ala GoF are about as usable to programmers as ornithology is to birds.

Re:The category design pattern by smadge on Sunday November 08, 2015 @03:47AM (#10527978)
> Philosophy of science is about as useful to scientists as ornithology is to birds

> Design patterns ala GoF are about as usable to programmers as ornithology is to birds.

So here design patterns is compared to philosophy of science. I think of design patterns more as a toolbox than an inapplicable study of the art. Much like how math is essential for science, I feel that solid programming abstractions and patterns are essential for software development.

Re:The category design pattern by fsloth on Sunday November 08, 2015 @05:58AM (#10528178)
"I feel that solid programming abstractions and patterns are essential for software development. "

Yeah, I feel exactly the same. To me object oriented programming as served by C++/Java/C# is good and fine for building abstractions over existing systems.

System design however, is served much better by thinking the system in terms of fundamental data structures, graphs and relational models rather than as an obtuse object hierarchy of some sort. This is my main gripe with GoF - it's used as a some sort of toolbox for software design when actually it just explains how to convert familiar and non-seremonial idioms from other languages to C++'s verbosity. If the student is not exposed to software construction in these other languages and just to GoF he/she is missing on so much (I know I did, at least).

But this is just my personal preference, maybe someone else writes much better software when thinking in objects but for me my initial years as a programmer were basically wasted in trying to build beautiful object hierarchies out of everything.

I write mostly C++ as my day job. Software modules which are built by embracing the C++ object model to it's full extent are the most horrible stuff I have to deal with :)

Re:The category design pattern by Retra on Sunday November 08, 2015 @12:08PM (#10529005)
I think the complaint is basically that the majority of GoF patterns are better solved simply by having first class functions, and many students won't realize this because they only know languages without them, so they never develop an intuition for seeing such simple ways of solving problems, and instead build complicated machinery to do trivial things. And GoF tends to legitimize this approach in their minds.

It's a good book, but it's not a book for beginners.

Re:The category design pattern by avz on Sunday November 08, 2015 @07:35AM (#10528329)
> Why was Rails successful?

I don't think Haskell aims for this kind of success.

Abstractions can be useful and they can be beautiful. If your goal is to "easily build functional CRUD apps" you need the former. If you do research in computing science or would like to further your understanding or simply seek to appreciate the elegance and beauty in computation, you need the latter.

Admittedly, the latter goals (except research) are self-directed (they may make you a better or at least a happier programmer) and they don't directly contribute value to your customers, so I understand why you just called them "mental masturbation". However, I strongly disagree with that label. There is a long-term value in learning and general self-improvement.

Re:The category design pattern by mbrock on Sunday November 08, 2015 @08:37AM (#10528443)
Unfortunately I don't know of much research in formalizing CRUD apps, but maybe it's out there.

The long-term wish as I see it would be for us as an engineering discipline to develop a really clear understanding of the domain, enough to be able to build these CRUD apps in composable ways that can be reasoned about with clear language.

Guiding vague questions might include: What is the essence of a CRUD app? How could you define a CRUD app in terms of sets, functions, and categories? What kinds of laws apply in the general CRUD domain? How can we statically verify correctness properties for real-world CRUD systems?

That hope has nothing to do with mental masturbation and everything to do with wanting to concretely improve the state of civilization. And of course to reduce the amount of time spent making and debugging the same kind of thing over and over again.

Re:The category design pattern by catnaroek on Sunday November 08, 2015 @12:43PM (#10529150)
I am by no means a researcher, but, as a programmer who writes said CRUD apps for a living, I can guarantee that I derive most of my understanding of a complex business domain from the structure of the relational database backing it. And what is a relational database? A (time-evolving) subcategory of the category of finite sets! Primitive types (as sets of values) and tables (as sets of primary key values) are objects. Fields (as functions of primary keys) are morphisms. Chained foreign key traversal is morphism composition.

I find this way of reasoning incredibly powerful, because it tells me quickly what kind of transactions make sense in a business domain. Of course, this is contingent on the database being well designed. It is exactly the same as with Haskell types - if you can leverage the (type system) schema to encode interesting logical properties of your (problem) business domain, then (type checking) checking a query against the schema in itself becomes a lightweight form of formal verification.

One thing that must be remarked, however, is that, sadly, SQL lacks analogues of sum and product types, that is, tables whose cardinality (number of rows) is the sum or product of the cardinalities of other tables. This addition would make SQL even more powerful, but it would require a move to a more category-theory-based foundation for databases. (The relational model is based on first-order logic.)

Re:The category design pattern by spion on Sunday November 08, 2015 @03:39PM (#10529788)
Isn't a join of two tables essentially the product of the two tables?

That said it does appear that sums are missing. Infact it seems like every mainstream language manages to fail to add sum types for some strange reason and you have to recreate them from scratch.

Re:The category design pattern by catnaroek on Sunday November 08, 2015 @03:50PM (#10529838)
An unconstrained `join` is indeed the product of two queries, and a `union all` can be used to get their sum as well. This is in the query language. But what I need is sums and products in the table language.

There is a functor from the category of tables to the category of queries, which maps every table `foo` to the query `select * from foo`, however, a table isn't the same thing as a query: table fields may contain user-entered data, whereas query fields are always computed from table fields.

To give a concrete example, consider a database with two primitive tables, `male` and `female`. A primitive table is “independent” in the sense that you can add or remove rows from it at will. In other words, a primitive table behaves just like a normal SQL table.

Now define the derived table `person` as the sum of `male` and `female`. Because `person` is derived, you don't explicitly add or remove rows from it. Instead, every time you add or remove a `male` or `female`, a corresponding `person` also gets added or removed.

What I want is the ability to add the field `name` to the `person` table directly, without it existing in either `male` or `female`. You can't do this in SQL. The situation is similar for products.

Re:The category design pattern by dragonwriter on Monday November 09, 2015 @06:54PM (#10536684)
> An unconstrained `join` is indeed the product of two queries, and a `union all` can be used to get their sum as well. This is in the query language. But what I need is sums and products in the table language.

The "table" language of SQL (DDL) includes pretty much the the entirety of the "query" language (DQL) through view definitions.

Of course, to do what you would really want to do to use relations to implement product and sum types, you needed materialized views with appropriate unique indexes for the candidate keys (and, ideally, auto-deriving the keys for product/sum tables from those of the base tables -- for product tables you can just concatenate the keys of the base tables, for sum tables you need the keys from the base tables to be equivalent and then to have an additional column that uniquely maps to the source table.)

Re:The category design pattern by catnaroek on Monday November 09, 2015 @10:07PM (#10537384)
A materialized view cannot contain user-editable fields unless these fields actually come from some actual table. Hence, a materialized view isn't a table in its own right, let alone a sum or product table.
Re:The category design pattern by dragonwriter on Tuesday November 10, 2015 @12:14PM (#10540625)
> A materialized view cannot contain user-editable fields unless these fields actually come from some actual table.

"User-editable" is actually superfluous; this is true (or false) of read-write attributes in exactly the same way as it is of read-only attributes.

> Hence, a materialized view isn't a table in its own right, let alone a sum or product table.

You seem to be use "sum or product type" and "sum or product table" in somewhat unusual ways. Upthread, you suggested that sum and product tables were simply realizations of sum and product types by way of tables; but sum and product types have domains that are, respectively, the sum or product of the domains of the set of types each is based on, they don't include additional data.

The kind if augment sum or product relation you seem to be referring to can be achieved in a relational database through views (including, to the extent useful to the application at hand, materialized/indexed views), where the "base" sum or product type is a materialized view as described in the grandparent comment (including the described indexes), and the additional fields are supplied through a related table with a foreign key constraint (the augmented sum/product being represented with a view that joins that table to the base sum/product view.)

Re:The category design pattern by catnaroek on Tuesday November 10, 2015 @01:03PM (#10541049)
In general, to say that a category has sums and products, these sums and products must be objects of the same category. The axioms for a category are totally agnostic to the concrete nature of its objects. Just because Hask objects are types, it doesn't mean objects in other categories are Haskell types of behave like Haskell types. In the context of databases, it makes sense to treat a schema as a category whose objects are its tables, and whose morphisms are chained foreign key traversals. And tables contain fields that carry data of their own.
Re:The category design pattern by spion on Sunday November 08, 2015 @04:24PM (#10529996)
I still don't understand. What you call derived tables seem like views to me. They always need to be composed of primitive tables. So there will be a primitive `name` table and the person view will be `name * (male + female)`... Admittedly everything will be in 6NF but it still seems doable. Is there a limitation that I'm missing?
Re:The category design pattern by catnaroek on Sunday November 08, 2015 @05:14PM (#10530216)
Sorry for the delay. I wasn't really thinking of making a primitive table just for names - what would its primary key be anyway?

The limitation you're missing is that SQL doesn't let you readily associate a user-entered `name` with each `person`. The best you can do is put a `name` field in the `male` table, then another `name` field in the `female` table, and use both `name`s when defining a `person` view. In my opinion, this is inelegant.

What I'm thinking about can be illustated with the following gist: https://gist.github.com/eduardoleon/1e8ad9174ec5ae0386dd

Re:The category design pattern by spion on Sunday November 08, 2015 @10:31PM (#10531228)
Created a fork with a solution.
Re:The category design pattern by catnaroek on Monday November 09, 2015 @04:27AM (#10532073)
It isn't apparent from my identifiers, but, in my `existing.sql`, `person`'s real primary key isn't just `person_id`, but rather `(gender, person_id)`.

The way you've handled it, now you have an invariant to maintain that `male_id`s and `female_id`s don't collide. If you want to define arbitrarily many sum tables in your database, this can be really hard to enforce. My `proposed.sql` doesn't have such a problem.

Re:The category design pattern by spion on Monday November 09, 2015 @11:26AM (#10533915)
Right, which is why I initially said that sum types (disjoint unions) are missing :)
Re:The category design pattern by catnaroek on Monday November 09, 2015 @12:32PM (#10534402)
Product tables are missing too. Let's say you have tables `foo` and `bar`. For every `foo` and every `bar`, you want the user to specify a `qux` value. Presently, what you need to do is:

(0) Create a table `foo_bar`, with fields `foo_id`, `bar_id` and `qux`. In particular, `qux` must be nullable. [Yuck!]

(1) Add triggers to `foo` and `bar` that automatically insert or delete rows from `foo_bar`.

(2) Hope [I'm not joking] the user remembers to set all the `qux` values in `foo_bar` whenever he inserts a row into either `foo` or `bar`.

Re:The category design pattern by tome on Monday November 09, 2015 @06:58AM (#10532531)
How does SQL lack product tables? The product of the column spec (foo int, bar bool) with the column spec (baz text, quux date) is the column spec (foo int, bar bool, baz text, quux date).
Re:The category design pattern by catnaroek on Monday November 09, 2015 @10:03PM (#10537363)
A column specification isn't a table. A table contains user-editable fields. If you have two SQL tables and compute their Cartesian product, the result is a query, not a table.
Re:The category design pattern by tome on Tuesday November 10, 2015 @02:23PM (#10541683)
Could you describe precisely the category that you are talking about and explain why it doesn't have sums and products?
Re:The category design pattern by catnaroek on Tuesday November 10, 2015 @04:44PM (#10542777)
The category I'm talking about has tables as objects, and chained foreign key traversals as morphims.

In SQL, this category is freely generated ( https://en.wikipedia.org/wiki/Free_category ) from a quiver ( https://en.wikipedia.org/wiki/Quiver_%28mathematics%29 ) whose nodes and edges are SQL tables and foreign keys, respectively.

In my proposal ( https://gist.github.com/eduardoleon/1e8ad9174ec5ae0386dd ), the category is still freely generated, but from something that has more structure than a quiver - some nodes may be designated as coproducts or products of other nodes.

In either case, the category can't possibly have all coproducts and products, and that's okay with me - a database can only have finitely many tables, after all. My beef with SQL is that it doesn't allow this category to have any coproducts and products at all.

Re:The category design pattern by tome on Wednesday November 11, 2015 @06:49AM (#10546142)
What do you mean by "SQL tables"? Presumably not the type of a table (you rejected that notion when I proposed it under the name "column specification") but rather a table with all its data?
Re:The category design pattern by catnaroek on Wednesday November 11, 2015 @12:07PM (#10547657)
Yes, by “SQL table”, I mean the table itself, with all its data. I don't think it's useful to think about “the type of a table”. Rather, I view tables as types in their own right - a table is the type of its rows.

I can see why this would seem weird from a Haskell perspective. Haskell encourages the programmer to view types as static collections of values. That is, normally, Haskell types don't get new inhabitants as your program runs. There are exceptions to this rule, like `IORef`s and `STRef`s, but idiomatic Haskell doesn't use these much AFAICT.

However, in Standard ML, some (static!) types are dynamically evolving collections of values. For example, if the control of flow reaches the line `exception Foo of string`, a new constructor `Foo` is added to the existing `exn` type. (As for why this is useful, see: https://existentialtype.wordpress.com/2012/12/03/exceptions-... ) Or, if the expression `ref x` is evaluated, where `x` has type `foo`, then the type `foo ref` gets a new inhabitant - a freshly created mutable cell initially containing `x`.

“Tables as types” is just reusing the idea of dynamically evolving (static!) types in a database context. Inserting or deleting rows from your `customer` table changes its collection of inhabitants, but it doesn't change the fact that there is a single type of customers.

Re:The category design pattern by mjw on Sunday November 08, 2015 @04:01PM (#10529887)
Eh...

    SELECT a.*, b.* FROM a CROSS JOIN b;

    (SELECT 'a' AS tag, * FROM a) UNION (SELECT 'b' AS tag, * FROM b);
Re:The category design pattern by catnaroek on Sunday November 08, 2015 @04:09PM (#10529930)
As I mentioned in my comment below: https://news.ycombinator.com/item?id=10529838 , the category of SQL queries has coproducts and products, but the category of SQL tables does not. Coproduct and product tables are very useful in their own right.
Re:The category design pattern by mjw on Monday November 09, 2015 @06:44PM (#10536647)
Ah OK, fair enough.

Not sure what definition you're using for the category of tables, but I don't think the distinction between table and query is really that significant, at least from a theory point of view. You can declare views and materialized views. In some SQL dialects you can even define triggers which allow you to 'update' them, not that I would have thought mutability would be particularly nice to reason about in a category-theoretic framework.

If you really want to do theory on this stuff, just use the relational algebra, or better yet just plain first-order logic. Much nicer, you have all the products and coproducts you want, and the results can probably be re-applied to SQL with a bit of cludge-work :)

Re:The category design pattern by catnaroek on Monday November 09, 2015 @10:09PM (#10537389)
Triggers are an imperative hack. This is like using a C struct with an enum and a union, and claiming that C has "sum types".
Re:The category design pattern by mjw on Tuesday November 10, 2015 @08:08PM (#10544047)
Agreed that SQL is ugly as hell, but if you want to talk about its theoretical properties that's a separate debate. Theory doesn't care whether something's aesthetically pleasing, just whether it's possible.
Re:The category design pattern by gaius on Sunday November 08, 2015 @04:30AM (#10528056)
Monads are a common joke to this effect.

So much so that I wonder if the popular monad tutorial involving spacesuits and burritos wasn't actually made as a pisstake (but I am 99% sure the author was serious).

Re:The category design pattern by danidiaz on Sunday November 08, 2015 @04:51AM (#10528085)
You might be interested in the inverse burrito-monad tutorial: http://www.cs.cmu.edu/~edmo/silliness/burrito_monads.pdf
Re:The category design pattern by porker on Sunday November 08, 2015 @07:10AM (#10528288)
> Sandy Metz doesn't get heard if DHH isn't building Basecamp.

Eh? Are you saying Sandy Metz isn't good, and needs DHH to provide a platform?

Disclosure: I have read POODR and am not sure what to make of it, as it's pragmatic but says the opposite of other OOP books I've read

Re:The category design pattern by throwawayignt on Sunday November 08, 2015 @08:44AM (#10528453)
>> Category theory codifies this compositional style into a design pattern, the category.

>To the average person, a theory codifying a style into a pattern just isn't useful

But you don't mean "the average person", you mean "the average competent programmer."

For example I'm not an "average person" and I don't understand the sentence you linked (the one I quote at the top of this comment.) It's just gobbledegook to me, the way a bit mask is to someone who doesn't know what bits are exactly, they're just, like, 1's and 0's in the computer right? You have to explain a lot before they would even understand what you're talking about. They might not know what a power of 2 has to do with anything.

This is an analogy. It's the same - average competent programmers don't have this mental infrastructure. I and most competent programmers have no idea what a category is.

Re:The category design pattern by omginternets on Sunday November 08, 2015 @09:45AM (#10528586)
>I and most competent programmers have no idea what a category is.

By your own admission, you have no idea whether or not category theory is useful to you.

Take pride in your ignorance if you like, but at least don't claim to know what you're talking about in the same breath.