News for hackers. Stuff that matters.
Re:Implement with Types, Not Your Brain by TheAsprngHacker on Tuesday June 25, 2019 @09:06PM (#20280969)
The submission mentions "theorems for free," which answers your question. The a and b type variables can be any type. Because the code has to work for anything, there are not too many operations that you can do on the values of types a or b. For example, if x :: a, you can't do x - 1 because that would require the constraint Num a.
Re:Implement with Types, Not Your Brain by taneq on Tuesday June 25, 2019 @10:16PM (#20281304)
Still seems to me (and I feel that the volume of discussion on this point confirms it) that this approach has a higher cognitive load than doing things slightly less abstractly and slightly more explicitly.
Re:Implement with Types, Not Your Brain by avmich on Wednesday June 26, 2019 @12:22AM (#20281896)
I guess the volume of discussion can be attributable to that there are enough Haskellers and enough non-Haskellers.

Haskellers read some texts and got used to the idea of type manipulations. They know, for example, there is a type "Void" which doesn't contain any values - that is, by definition no object has this type - and therefore any function which has this type of argument can't be invoked. Because to invoke the function, it has to be passed a value of the given type, and there aren't any.

Haskellers got used to the idea that if we have function from type a to the same type a, and there are absolutely no restriction on what the type a is, then it should be identity function - they just sat on this idea, pondered it for some time and got to this conclusion. For non-Haskellers it's not clear - and even the idea that types can restrict code so tightly as to make code unique (up to isomorphisms) can be novel to them.

Does it make a bigger cognitive load? Probably not for those who got used to type properties like this. Is it hard for non-Haskellers to see this feature and try to use it? Well, many Haskellers passed through this stage, so it ought to be doable. Most importantly, can they agree on this?..

Re:Implement with Types, Not Your Brain by mrkeen on Wednesday June 26, 2019 @05:04AM (#20283130)
Abstraction is about eliminating the details, not ignoring them.

If I have ((a,b)->b), it behaves precisely the same way regardless of what those variables represent.

Do I need to do null check? Irrelevant. B is being reused, do I do a deep or a shallow copy? Does it have a copy constructor? Irrelevant.