Created
January 29, 2016 02:12
-
-
Save chadaustin/465acf1f1c5680cfe4f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE ExistentialQuantification, LambdaCase #-} | |
| import Data.IORef | |
| import Control.Monad | |
| data Mover = forall a. Mover (IORef [a]) (IORef [a]) | |
| doMove :: Mover -> IO () | |
| doMove (Mover left right) = do | |
| readIORef left >>= \case | |
| [] -> return () | |
| (x:xs) -> do | |
| writeIORef left xs | |
| modifyIORef right (x:) | |
| main = do | |
| a1 <- newIORef ["foo", "bar"] | |
| a2 <- newIORef [] | |
| b1 <- newIORef [1, 2, 6] | |
| b2 <- newIORef [] | |
| let movers :: [Mover] | |
| movers = [Mover a1 a2, Mover b1 b2] | |
| forM_ movers doMove | |
| readIORef a1 >>= putStrLn . show | |
| readIORef a2 >>= putStrLn . show | |
| readIORef b1 >>= putStrLn . show | |
| readIORef b2 >>= putStrLn . show | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment