Neat! I also cloned 2048 in Haskell [1]. I don't know how many lines of code it is, but the core game logic is remarkably simple. [1]: http://taylor.fausak.me/2014/04/28/cloning-2048-in-haskell/
shift v = pad
(map Just (concatMap add (group (catMaybes v)))))
Nothing
(length v)
whereas the code gives: shift v = take n (v' empty n)
where
n = length v
v' = group (filter isJust v) >>= go
go (Just a : Just b : ts) = Just (a + b) : go ts
go ts = ts
From my understanding of the blog post's logic, the former doesn't handle the case where `v = replicate 4 (Just 2)`, since it returns `[Just 4, Just 2, Just 2, Nothing]`. Am I correct, and if so, why does the latter version fix this problem? For reference, I know little to no Haskell.