July 2017
Intermediate to advanced
284 pages
6h 45m
English
Let’s see how much Haskell you can understand just by first grasping an informal, hand-wavy solution and then looking at the corresponding code. It’s very much a “think in data” solution, but also probably quite different from how you’ve seen this kind of problem approached before. Without modulo division or if statements, I give you “Functional Fizz Buzz.”
The task is this: you want Fizz every three steps, and Buzz every five steps. We note that sometimes the cycles coincide. Let’s talk cycles then.
| | threes = cycle ["", "", "Fizz"] |
| | fives = cycle ["", "", "", "", "Buzz"] |
cycle is defined like this (the real library def is more efficient, but less clear):
| | cycle xs = xs ++ cycle xs -- SIMPLE version of lib |
So threes just ...
Read now
Unlock full access