Hacker News new | ask | show | jobs
by baguasquirrel 6199 days ago
I'm really curious to see how other people are progressing through the learning process for Haskell (and other HM-based functional languages). I rarely use lambdas, and I feel that Haskell is much easier to read than to write. Clearly there's something different about our approaches. I learned SML back in school, picked up OCaml about 3 years ago, and picking up Haskell was still a bit of a trip.
2 comments

I also find I use lambdas less in Haskell than in other languages. I think it's because in Haskell, constructs like partial application, function composition or lifting are concise and natural to express, and those constructs cover most common use cases for an anonymous function. I think

map (find needle) haystacks

is clearer (as well as shorter!) than

map (\haystack -> find needle haystack) haystacks

In most other languages things like partial application are a pain to express, so a lambda is an easier way out.

(Now I'm imagining the six lines of Java I'd have to write to achieve the same effect as those four words of Haskell, and trying not to giggle. Functional style is addictive.)

Sorry - I meant that it makes me use lambdas in Python (you're right, I don't use many lambdas in Haskell either).

I find myself using them in Python everywhere as a substitute for currying and/or laziness, e.g.:

  def f(a,b): 
    ... # do stuff
  def g(a,b):
    ... # do other stuff
  meths = {'use f':f, 'use g':g}
  a = calculate_a()
  m = pick_a_method()
  x = do_cool_thing(data,lambda b: meths['m'](a,b))