Skip to content

Instantly share code, notes, and snippets.

@wavewave
Created July 10, 2013 17:35
Show Gist options
  • Save wavewave/5968364 to your computer and use it in GitHub Desktop.
Save wavewave/5968364 to your computer and use it in GitHub Desktop.
Store comonad idiom study with arrow combinators
import Control.Applicative
import Control.Arrow
import Control.Comonad
import Control.Comonad.Trans.Store
cget :: Store Int a -> Int
cget = pos
cput :: Store Int Int -> Store Int Int
cput wf = seek (extract wf) wf
w3 :: Store Int a -> String
w3 = show . pos
w4 = (cget >>> (+1)) =>= cput
main :: IO ()
main = do
putStrLn "comonad test"
let flow = ((cget >>> (+1)) =>= cput =>= (extract >>> ((w4 =>= (extract >>> w3)) &&& w3)))
print (flow (store (const ()) 0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment