7 ms·
Maybe I'm getting Haskell-blind, but what's "wierd" about the syntax? If I think about "wierd" syntax, I think about Erlang or Objective-C or Befunge for that
by eelco 18y ago
Maybe I'm getting Haskell-blind, but what's "wierd" about the syntax? If I think about "wierd" syntax, I think about Erlang or Objective-C or Befunge for that matter. However, it seems that once you spent a day or so with a language the syntax wierdness tends to go away. (Still need to test that hypothesis with Erlang, though.)
- lacker 18y agoPattern-matching for control flow rather than if statements is the main weird thing. E.g. sum ys = let sum' [] total = total sum' (x:xs) total = sum' xs (total+x) in sum' ys 0 That looks weird.
- silentbicycle 18y agoUnlike some other features* , pattern matching isn't all that scary, though. "Oh, it's like a switch statement... but it can break things up and check inside... that's pretty cool." You can understand it in terms of other fairly commonplace constructs, and it's relatively clear how useful it is. It could be presented a bit differently, but the underlying idea seems approachable. * I'm thinking of monads, in particular; whether they actually are or whether it's just due to the way they've been presented is another question.
- time_management 18y agoMonads aren't that hard. A monad is just like a burrito! Pattern matching is awesome. It makes code immensely more readable.
- silentbicycle 18y agoI started to understand monads when I compared the Maybe monad to the short-circuiting behavior of the Unix pipe. That doesn't mean my insight will work for anybody else, though. Also, having masses of Haskell blog posts saying, "No, monads are actually not that hard, here's (an explanation that probably won't actually make all that much sense)." probably doesn't help to dispel the myth that Haskell is hard / impractical / whatever.
- time_management 18y agoIn understanding monads, I think Maybe and List are the best places to start, because they're familiar data structures. IO is conceptually familiar, but IO as an immutable value representing a series of actions is not.
- silentbicycle 18y agoAgreed, strongly. Trying to understand monads in terms of IO makes things vastly more difficult than necessary.
- time_management 18y agoWell, just as "monads are like burritos", IO is like a delicious but sketchy fish taco. Eating is input. We shan't discuss the output process; we all know how it works and what it looks like. Food poisoning or poor health can lead to usage of standard error. In practice, stdout and stderr are usually redirected to the same buffer, which is flushed shortly after a write.
- ighost 18y agobrilliant.
- felixmar 18y agoA case expression is more common: sum ys = sum' ys 0 where sum' list total = case list of [] -> total x:xs -> sum' xs (total + x)
- wernerv0nbraun 18y agothis 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 ago
- tphyahoo 18y agosum ys = foldl' (+) 0 ys
- eru 18y agoCombinators for the win!
- wmf 18y agoPattern matching, also the lack of syntax for function calls (I realize there's a good reason for it).
- jimbokun 18y ago"lack of syntax for function calls" It recently dawned on me that this is what makes it hard for me to understand snippets of Haskell. Specifically, trying to parse the precedence relations in a sequence of tokens uninterrupted by any kind of punctuation. Say what you will about Lisp, it is always very clear which arguments go to which functions, what the scoping boundaries are, etc.