4 ms·
I'm not sure what your complaint is. import Control.Monad (forM_) fizzbuzz i | i `mod` 3 == 0 = Left "fizz" | i `mod` 5 == 0 = Left
by tome 12y ago
I'm not sure what your complaint is.
import Control.Monad (forM_)
fizzbuzz i | i `mod` 3 == 0 = Left "fizz"
| i `mod` 5 == 0 = Left "buzz"
| otherwise = Right i
main = forM_ [1..100] (\i -> either putStrLn print (fizzbuzz i))
- geofft 12y agoYeah, that certainly works, but one of Python's particular strengths (and in particular what the original article was about) is a teaching language. I certainly understand what you're doing there, but I wouldn't want to explain it on day 3 of high school CS class. :) The slightly cleaner thing here would be to take advantage of both strings and integers implementing Show. I'm thinking a bit about whether that would actually work well enough in a teaching language; possibly. (Although if I'm remembering my Haskell well enough, you need to enable existentially quantified types to make this work, which, again not really day-3 material. Probably works fine in like Rust, though.)