4 ms·
Syntax matters. What I really like about Haskell is how much care has been given to the syntax to make functional idioms easy to read and write. One can just sa
by yomritoyj 9y ago
Syntax matters. What I really like about Haskell is how much care has been given to the syntax to make functional idioms easy to read and write. One can just say,
fib = 0:1:zipWith (+) fib (drop 1 fib)
[I know that `drop 1` is just `tail`, but this one makes the intent clearer for those who may not know Haskell].
- Zpalmtree 9y agoTechnically drop 1 isn't just tail, but it doesn't matter in this example. Tail will error on an empty list.
- ubernostrum 9y agoYou can often get close to Haskell-y implementations in Python with help from the itertools module. There are a couple "Haskell style" Fibonacci generators with itertools floating around in blog posts, I'm sure, and I've used itertools to write all sorts of things in a pretty succinct manner.