2 ms·
The Haskell type `[x] -> [x]` (the equivalent of `List[A] -> List[A]`) tells you an incredible amount about the function. It tells you that the function must ca
by dwohnitmok 2y ago
The Haskell type `[x] -> [x]` (the equivalent of `List[A] -> List[A]`) tells you an incredible amount about the function. It tells you that the function must calculate a subset of a permutation of the input list. The function cannot be anything else (or else it will crash or hang). In a language with stricter requirements you can omit even the crash/hang caveat.
Don't underestimate the amount of information even simple type signatures contain!
- tromp 2y agoNot necessarily a permutation; e.g. f :: [a] -> [a] f [] = [] f (x:xs) = x: x: f xs
- tome 2y agoYeah, Hickey was just wrong about this. For me, watching his talks goes like this: Hickey: I value X, Y, Z Me: Yeah man! Hickey: We get great consequences A, B, C Me: Ah yeah, I love programming like that. That's why I love Haskell! Hickey: That's why Haskell is bad. Me: err, what!? > It tells you that the function must calculate a subset of a permutation of the input list As tromp pointed out, "permutation" is technically incorrect. You mean something like "a list formed only from elements of the elements of the input list, and the particular arrangement is independent of the values of the input list"! Not sure why you were downvoted though.
- MarkMarine 2y agoI think what he’s saying is the type signature alone isn’t enough, but in some languages like Haskell, people do imagine if the program type checks, it’s good. But that isn’t necessarily true, you need a ton of other context to actually have a proper functioning program, and the reverse function is an example of this. I didn’t say Haskell was bad though. I love Haskell in a different way from clojure.
- MarkMarine 2y agoRich’s point is the type signature actually tells you little about what the function does. You need the name, docs, tribal knowledge, your own understanding of the math… etc. to actually understand what it does. Type signature alone is a very incomplete understanding. But come on, do you think I learned how to write Haskell and don’t understand what a type signature’s value is? Give me a little credit. Here is Rich’s work on the subject: https://youtu.be/YR5WdGrpoug?si=7C8EjQ7TVo2Ua8w7 https://youtu.be/YR5WdGrpoug?si=7C8EjQ7TVo2Ua8w7 I’m biased, but I think he’s got a point.