(Though I do admit that I immensely like Lisp's macros.)
In e.g. Haskell abstractions are the straightforward way to solve a problem. Abstractions are cheap.
(Though I do admit that I immensely like Lisp's macros.)
In e.g. Haskell abstractions are the straightforward way to solve a problem. Abstractions are cheap.
Currying and combinators are my preferred ways of creating new functions. Having infix symbols can help a bit, but I don't see it as crucial.
Incidentally I only really began to use reduce/fold in Clean and Haskell, though I had been exposed to the concept in Scheme before, and used it a few times. But perhaps that was just a learning effect of prolonged exposure and would have happened while staying with Scheme, too.
I still like Scheme. Matthias Felleisen is doing great work using it for education.
Compare:
(define (list-reverse l) (foldl cons '() l))
listReverse = foldl (flip (:)) []
I hope both versions are fairly idiomatic.Here are two combinators that I have actually used in my code (the first one is fairly common):
dot :: (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
dot = ((.).(.))
swing :: (((a -> b) -> b) -> c -> d) -> c -> a -> d
swing = flip . (. flip id)
Imagine (or better: provide!) Scheme versions or their idiomatic equivalents.Of course the point-free definitions makes them a bit hard to understand, but I wanted to demonstrate terseness. `dot' also has a nice point-full definition:
dot f g a b = f (g a b)
The use case for `dot' should be obvious from the latter definition. I leave the point-full definition (and a use case) for `swing' as an exercise. Let me just note that Lisp would carry some more syntactic baggage for the definition and use of both of these combinators.However, you can't beat Lisp, when it comes to Quines:
((lambda (x) `(,x ',x)) '(lambda (x) `(,x ',x)))
Haskell's facilities for talking about Haskell code are more verbose.P.S. for completeness sake, to make the exercise above easier without doing a search:
id a = a
flip f a b = f b a