News for hackers. Stuff that matters.
Re:Hask is not a category by dietrichepp on Saturday August 06, 2016 @06:31PM (#12240190)
I would like to see an analysis of Hask when restricted in one of the following ways:

1. Only strict functions (f ⊥ = ⊥)

2. Only total functions (x ≠ ⊥ -> f x ≠ ⊥)

But otherwise, the notion that Hask is not a category is nothing new.

Re:Hask is not a category by TAForObvReasons on Saturday August 06, 2016 @06:58PM (#12240273)
> But otherwise, the notion that Hask is not a category is nothing new.

I'm not entirely sure. Read the official Haskell page on the subject: https://wiki.haskell.org/Hask

> In order to make Hask a category, we define two functions f and g as the same morphism if f x = g x for all x. Thus undef1 and undef2 are different values, but the same morphism in Hask.

If I understand the passage correctly, they are defining the morphism in a way that makes Hask a category. I think the author of the original post interpreted it the same way.

Re:Hask is not a category by dietrichepp on Saturday August 06, 2016 @09:20PM (#12240637)
It seems like the author isn't interpreting it the same way at all, because "(undefined . id)" would be the same morphism as "undefined" by the criteria on the wiki page, and then the author says that they must be different because you get different behavior when you pass them to "seq", which is a radically different set of criteria.

Which is exactly what is addressed by the wiki page... you get different behavior when you use "seq" on two different things which are the same morphism. The wiki page even uses almost the same example.

Re:Hask is not a category by catnaroek on Saturday August 06, 2016 @10:21PM (#12240774)
The problem is that the entire library ecosystem is built under false premises. It's annoying, because you occasionally stumble upon an abstraction leak, and then you need to take a really deep breath, climb down the abstraction ladder (which is pretty tall in Haskell's case!), and look for the exact place where something went wrong.
Re:Hask is not a category by dietrichepp on Saturday August 06, 2016 @10:56PM (#12240838)
I'm not convinced. All abstractions are leaky, you just have to decide whether a particular abstraction is useful or not in spite of its leaks. I think the problem you are talking about is the fact that Haskell code tends to have lots of abstractions built on top of other abstractions.

While this is definitely a problem in some Haskell code bases, you will also see your fair share of Haskell code which is closer to purely functional code or closer to straightforward imperative code.

Re:Hask is not a category by catnaroek on Saturday August 06, 2016 @11:01PM (#12240848)
> All abstractions are leaky,

I can tolerate abstraction leaks when the cost of using the non-leaky version is prohibitive. For example, I wouldn't want a language that constantly reminds me that memory allocation can fail. “Memory is infinite” is just too nice an abstraction, and I'm not going to let the fact it isn't true get in the way.

But I can't live with a mismatch between the language's intended and actual semantics. If the Haskell language, libraries and community promise me that Hask is morally the category of sets, then it better be morally the category of sets! Of course, this promise is impossible to fulfill in a language without a typefully delimited terminating subset, so Haskellers better scale down their ambitions to something actually realizable.

> I think the problem you are talking about is the fact that Haskell code tends to have lots of abstractions built on top of other abstractions.

No, I don't mind high abstraction towers - I actually like them, in fact! What I hate is climbing them down because some abstraction leaked somewhere.

> you will also see your fair share of Haskell code which is closer to purely functional code or closer to straightforward imperative code.

Since when is imperative code straightforward? Reasoning about purely functional programs: high school algebra, plus induction over datatypes. Reasoning about imperative programs: Hoare logic. The facts speak for themselves.

In any case, this has nothing to do with functional vs. imperative. It's just “please don't impose cognitive dissonance on me!”

Re:Hask is not a category by dietrichepp on Sunday August 07, 2016 @12:39AM (#12241075)
That's a really disingenuous interpretation of "straightforward". If you don't want to have a real conversation then just don't bother replying next time.
Re:Hask is not a category by catnaroek on Sunday August 07, 2016 @12:48AM (#12241095)
> If you don't want to have a real conversation

I wanted to have a real conversation, but, given the hostility in your response, I'll stop.

Re:Hask is not a category by dietrichepp on Sunday August 07, 2016 @01:23AM (#12241171)
Hostility was exactly what I read in your comment about Hoare logic.
Re:Hask is not a category by tome on Sunday August 07, 2016 @07:34AM (#12241785)
I really don't know what's got into you. You've clearly got some great ideas about what's valuable in programming languages. If you took the time you spent making vague complaints about Haskell and instead spent it pointing out concrete flaws, their consequences, and how to fix them, then we'd all be much better off. I would encourage you to do that.
Re:Hask is not a category by tome on Sunday August 07, 2016 @07:31AM (#12241779)
> you occasionally stumble upon an abstraction leak, and then you need to take a really deep breath, climb down the abstraction ladder

Can you give an example?

Re:Hask is not a category by catnaroek on Sunday August 07, 2016 @03:04PM (#12243182)
For most type classes and instances, the proofs that the corresponding laws hold break horribly if you substitute their free variables with nonterminating computations. For instance, `0 * x = 0` doesn't hold if `x` is `undefined`.
Re:Hask is not a category by tome on Sunday August 07, 2016 @06:12PM (#12243984)
How would a strict language help? `0 * x = 0` doesn't hold if `x` is substituted by a non-terminating computation `f ()`. What exactly would be the benefit?
Re:Hask is not a category by catnaroek on Sunday August 07, 2016 @07:22PM (#12244331)
In a strict language, non-terminating computations aren't values in the first place. So you can't substitute `x` with bottom.
Re:Hask is not a category by tome on Monday August 08, 2016 @03:21AM (#12245979)
I don't think I've grasped the distinction between substituting a variable of type t with a value of type t versus an expression of type t.
Re:Hask is not a category by catnaroek on Monday August 08, 2016 @04:54AM (#12246328)
There's no such distinction. But, in the operational semantics of a call-by-value language, variables are only substituted with values.

Or, to be consistent with the terminology I've used in other comments, in any language, a value is something a variable can be substituted with. It's just that, in a call-by-value language, variables can never be substituted with unfinished computations.

Re:Hask is not a category by sclv on Sunday August 07, 2016 @05:22PM (#12243720)
You do get 0 * x <= 0. You just need a splash of domain theory to make the medicine go down.
Re:Hask is not a category by tome on Sunday August 07, 2016 @06:12PM (#12243985)
I don't think that's the <= you were looking for ...