3 ms·
this haskell example is exposing you to two cool things: - algebraic types. haskell has type inference, so it can do the right thing while you only describe th
by wernerv0nbraun 18y ago
this haskell example is exposing you to two cool things:
- algebraic types. haskell has type inference, so it can do the right thing while you only describe the function as operating on lists. now look at java...strong typing but no intelligent inference, which is why you are forced to write retarded java like HashSet<Integer> s = new HashSet<Integer>()
- pattern matching. you can describe functionality based on the pattern of the data
this isn't just syntax. these are really powerful fundamental features of the language
- brl 18y agoRetarded? Really? I guess that you don't know that generics in Java were derived from Haskell type classes and designed by the same man who added monads to Haskell.
- fhars 18y agoRetarded, indeed. Almost half of that code is a redundant repetition of type information.
- brl 18y agoIt's not redundant information and in Haskell you write exactly the same thing. doSomething :: HashSet Int -> HashSet Int
- wernerv0nbraun 18y agono again. in the case of a haskell analogue to HashSet (Set, Map, etc), you could use type inference due to haskell's type classes. go look at the definitions of these libraries, they use them.
- eru 18y agoHe had to work in the constraints of the language..
- jganetsk 18y agoAnd that man would absolutely love it if Java had a type system closer to Hindley-Milner with type inference. But, given the reality of Java, generics become undesirably verbose.
- brl 18y agoA typical well written Haskell program has more type annotation than the same program written in Java. Not only that but because of type classes those annotations are even more verbose than an equivalent declaration in Java. It's true that you can omit most of the type signatures and let the compiler figure it out but nobody really writes Haskell code that way if they want it to be comprehensible by human readers.
- silentbicycle 18y agoI've wondered about this. It seems common for OCaml code to only have the type annotations where necessary, but it's usually included in Haskell by convention.
- lacker 18y agoYes, I totally agree. But the question I was responding to was just, "What parts of Haskell have weird syntax?" All of this cool stuff would also be possible with c-like syntax.