Created
June 19, 2014 09:29
-
-
Save angelworm/dad37a195d19eff65011 to your computer and use it in GitHub Desktop.
男装の麗人
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
import Control.Monad | |
import Control.Applicative | |
import Control.Monad.State | |
import Control.Monad.Writer | |
newtype A = A [B] deriving(Show) | |
newtype B = B Int deriving(Show) | |
type Checker a = StateT Int (WriterT [String] Maybe) a | |
w = lift . tell . return | |
f = lift . lift | |
checkA :: A -> Checker A | |
checkA (A b) = A <$> mapM checkB b | |
checkB :: B -> Checker B | |
checkB (B c) | c == 0 = B <$> (w "hoge" >> return 13) | |
| c == 1 = B <$> (w "huga" >> return 13) | |
| c == 2 = B <$> get | |
| c == 3 = modify (*2) >> return (B c) | |
| c == 4 = B <$> (f Nothing) | |
| otherwise = B <$> return c | |
run = execWriterT $ evalStateT (checkA $ A $ map B $ [2,3,2,3,2,0,0,1,3]) 100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment