Skip to content

Instantly share code, notes, and snippets.

@danlaudk
Created May 27, 2017 20:23
Show Gist options
  • Save danlaudk/acc55550b36c0d6de517e9e10cf786d2 to your computer and use it in GitHub Desktop.
Save danlaudk/acc55550b36c0d6de517e9e10cf786d2 to your computer and use it in GitHub Desktop.
forth at rc wk1
-- Control.Monad.State.Strict
import Control.Applicative (liftA3)
import Control.Monad (replicateM)
import Control.Monad.Trans.State
type Stack = List[Int]
pop :: State Stack Int
pop = state $ \x ->
case x of
head::tail -> (head, tail)
_ -> (0, [])
swap = do
a <- pop
b <- pop
_ <- push b
_ <- push a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment