65 points · by fogus · 15y ago · 51 comments
There's still some room for Haskell syntax improvements. I've found the recent OverloadedStrings to be a big step forward, allowing you to directly use strings in places where it actually wants another type, removing a ton of useless and hard-to-factor-out code converting strings to ByteStrings, Text, and various other types that are there simply to label Strings as something more specific.
As dfrankes says, it is known the Prelude isn't perfect, but I'm not sure there's actually a perfect formulation regardless of what you do. Even if you could get all the mathematicians to agree completely about what all relevant mathematical entities are, something that is a lot harder than it sounds because it turns out a lot of them can have arbitrarily-chosen fiddly details when you really get down to it (how many set theories are there again?), you'll never bridge the gulf between a conventional programmer and any mathematician, and I think Haskell's promise as an interesting language lies rather more with the conventional programmer case than making mathematicians happy. (Not because the latter is bad, but because it is a sufficiently hard problem that trying to reconcile the needs of such a beast with something still useful is probably impossible.)
I love how you, in the same sentence, managed to put in doubt credibility of the upvoters and downplay the issue in hand.
To answer your question: yes, I actually read the article. Why I upvoted it? Haskell's way of wrapping integer literals with implicit `fromInteger` seems to be a clever hack that alleviates some pain when dealing with basic arithmetics, but I always wondered what kind of unexpected problems it may cause. I got an answer in this article.
No, I don't. The issue is serious. I'm personally a proponent of tossing the current Prelude and replacing it with something more useful. I think the supposed costs are smaller than expected (it's already modular) and the benefits underestimated. I'm not a Haskell booster, I'm an interested skeptic.
I just think an article about a relatively esotoric issue about Haskell got upvoted suspiciously quickly on a holiday weekend. It's not a bad article by any means.
[1 of 1] Compiling Main
Ok, modules loaded: Main.
*Main> p [1,2,3,4,5]
<interactive>:1:11:
Ambiguous type variable `t' in the constraints:
If however you substitute `Integer` for `Int`, which is after all what he claims to have meant, then suddenly: [1 of 1] Compiling Main
Ok, modules loaded: Main.
*Main> p [1,2,3,4,5]
(5x^4 + 4x^3 + 3x^2 + 2x + 1)
*Main> :t it
it :: UnivariatePolynomial Integer
It seems, then, that if he had known that in Haskell the 'integer' type is called Integer, not Int, he wouldn't have had any difficulty, or any blog post, or any occasion unjustly to malign his teachers `conal` and `mauke`, to whom he ought rather to be grateful.Besides, now we've all got a good excuse for why we've not learned Haskell yet: the type system is like so broken ;)
Integer i = new Integer(5);
I mean, look at how concise and readable that is. Java knows that 5 is an Integer and you don't even have to tell it.Oh wait, the opposite.
Basically, the author seems upset that "5" is a Number rather than an Integer. But that's fine, because it's true. 5 is a real fraction. 5 is a complex fraction. 5 is a double. 5 is a char. 5 is an unsigned long long. 5 is a lot of things to a computer. So sometimes, you have to tell it which one you want.
This isn't cargo-cult mathematics, but rather reflects that Haskell is a computer programming language. There is a lot of math in there, sure, but at the end of the day, you are writing computer programs to run on computers. And computers don't know what an Integer is. It just knows that it has some bits in memory and that it should interpret them in a certain way.
This guy's blog is weird.
A contributing factor here is that there are no subtype relations in Haskell. In math, "5" is all of those things simultaneously, but in Haskell it can only be one at a time.
How is that?
Excerpts from ghci dialog:
Prelude> :t 5
5 :: (Num t) => t
class (Num a) => Fractional a where
(/) :: a -> a -> a
recip :: a -> a
fromRational :: Rational -> a
Prelude Data.Complex> :i RealFrac
class (Real a, Fractional a) => RealFrac a where
...
Prelude Data.Complex> :i RealFloat
class (RealFrac a, Floating a) => RealFloat a where
...
Prelude Data.Complex> :i Complex
data (RealFloat a) => Complex a = !a :+ !a
instance (RealFloat a) => Eq (Complex a)
So, 5 is an Int, Integer, Rational, Double and Complex (which, actually, could be Complex Int or Complex Double).But nobody said that Haskell's type system is without limitations, right?
"So I call these things cargo cult science, because they follow all the apparent precepts and forms of scientific investigation, but they're missing something essential... It's a kind of scientific integrity, a principle of scientific thought that corresponds to a kind of utter honesty... In summary, the idea is to try to give all of the information to help others to judge the value of your contribution; not just the information that leads to judgment in one particular direction or another."
This is not an example of 'cargo-cult', because we are not dealing with people going through motions without knowing why. Asserting such is just insulting the creators of Haskell/the Prelude/standard Haskell classes, who are obviously making trade offs and perhaps, gasp mistakes. Being wrong, impure or simply making choices some others disagree with does not make one a 'cargo cult' anything. Feynman must be turning in his grave.
By "appropriate," I meant to suggest the author's usage of it can be construed as consistent with Feynman's meaning. I linked the source so folks could decide for themselves if the author's claim was correct in addition to having a meaning we could all agree on.
[I don't know anything about Haskell, I was just trying (and apparently failing) to clarify some muddy discourse.]
Yup, just like you do in most statically typed languages.
(* Standard ML of New Jersey v110.72 [built: Sun May 16 15:16:12 2010] *)
- 5;
val it = 5 : int
(* Objective Caml version 3.11.2 *)
# 5;;
- : int = 5
// D programming language
void main(string[] args){
writefln(typeid(typeof(5)));
}
// Output: int
// C# 4.0
var n = 5; // int
// Go programming language
var n = 5 // int
// Welcome to Scala version 2.7.7final (OpenJDK 64-Bit Server VM, Java 1.6.0_20).
scala> 5;
res0: Int = 5
// C++
#include <iostream>
#include <typeinfo>
int main(){
cout << typeid(5).name() << endl;
return 0;
}
// Output: i
I see... // GHCi, version 6.12.3: http://www.haskell.org/ghc/
Prelude> :set +t
Prelude> 5
5
it :: Integer :set +t"Well, we have a list of integers [Math Processing Error]. And [Math Processing Error] for monoid [Math Processing Error]. So [Math Processing Error] since [Math Processing Error] is a monoid, yes? Of course."
[1,2,3,4,5] :: [Int] problem solved!
In GHCi (the interpreter) this doesn't happen. It has some defaulting rules to alleviate this, but I don't quite understand them, so I can't say why they didn't kick in in this case.
One of the first things you learn as a Haskell programmer is to treat type inference with suspicion.
I appreciate that his goals were more mathematically oriented than not, but surely he would've seen something like this coming?