Re:Implementing 2048 in 90 lines of Haskell
by jabagawee on Sunday June 15, 2014 @10:49PM
(#7897175)
Oh! So `go` is a function that's defined within `shift`. That's the crucial part I was missing. Why is it named "go"?
EDIT: While I have your attention, do you mind also pointing me to some resources to learn about this ">>=" operator? I recall it's something related to monads...
Re:Implementing 2048 in 90 lines of Haskell
by taylorfausak on Monday June 16, 2014 @09:28AM
(#7898902)
As ibotty said, I named the anonymous inner worker function `go`. From what I can tell, it seems to be pretty common in Haskell.
As for `>>=` (also known as `bind`), I'm using it as a more generic version of `concatMap`. The following expressions are basically the same:
concat (map (\ x -> [x, -x]) [1, 2, 3])
concatMap (\ x -> [x, -x]) [1, 2, 3]
[1, 2, 3] >>= \ x -> [x, -x]
If you want to learn more, check out LYAH [1].`go` is a very old name for worker functions in haskell. i have been told it originates in glasgow (where ghc was first developed).
The problem in the blog post is the `add` function. It should recurse (like `go` in the Hs2048 package). I fixed the post [2] with this line:
[1]: https://gist.github.com/tfausak/4401ef0b43b5c1db0570 [2]: https://github.com/tfausak/tfausak.github.io/issues/31