Last active
February 4, 2018 11:38
-
-
Save kakkun61/4bbc966ede75c98109fd2c136dc0499a to your computer and use it in GitHub Desktop.
手続き Haskell
This file contains 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
module Main where | |
import Prelude hiding (break) | |
import Control.Monad (when) | |
import Control.Monad.Cont (callCC, ContT, runContT) | |
import Control.Monad.IO.Class (liftIO) | |
import qualified Data.Foldable | |
import Data.IORef (newIORef, readIORef, writeIORef) | |
import qualified Data.Traversable | |
main :: IO () | |
main = do | |
nRef <- newIORef (0 :: Int) | |
for_ [1 .. 9] $ \i break -> do | |
n <- liftIO $ readIORef nRef | |
let n' = n + i | |
when (n' > 40) break | |
liftIO $ writeIORef nRef n' | |
n <- readIORef nRef | |
print n | |
for_ :: (Foldable t, Applicative f) => t a -> (a -> ContT () f () -> ContT () f ()) -> f () | |
for_ t f = flip runContT pure $ callCC $ \cc -> Data.Foldable.for_ t (flip f $ cc ()) | |
for :: (Traversable t, Applicative f) => t a -> (a -> (t b -> ContT (t b) f c) -> ContT (t b) f b) -> f (t b) | |
for t f = flip runContT pure $ callCC $ \cc -> Data.Traversable.for t (flip f cc) |
This file contains 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
name: procedural | |
version: 0.1.0.0 | |
-- synopsis: | |
-- description: | |
-- homepage: | |
license: BSD3 | |
-- license-file: LICENSE | |
author: Kazuki Okamoto | |
maintainer: kazuki.okamoto@kakkun61.com | |
copyright: 2018 Kazuki Okamoto | |
-- category: | |
build-type: Simple | |
-- extra-source-files: | |
cabal-version: >=1.10 | |
executable procedural | |
hs-source-dirs: . | |
main-is: Main.hs | |
ghc-options: -threaded | |
-rtsopts | |
-with-rtsopts=-N | |
-Wall | |
-Wincomplete-uni-patterns | |
-Wincomplete-record-updates | |
-Wmonomorphism-restriction | |
-Wimplicit-prelude | |
-Wmissing-local-signatures | |
-Wmissing-exported-signatures | |
-Wmissing-import-lists | |
-Wmissing-home-modules | |
-Widentities | |
-Wredundant-constraints | |
-Wno-implicit-prelude | |
build-depends: base | |
, mtl | |
default-language: Haskell2010 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment