Created
February 20, 2019 23:03
-
-
Save boj/519ee61dca1c7e034126ddc6776fd2e0 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
| module Main where | |
| import Control.Monad.Writer | |
| import Control.Monad.Except | |
| import Data.Functor.Identity | |
| f :: Monad m | |
| => (String -> String -> m String) | |
| -> String | |
| -> String | |
| -> m (Either String (), [String]) | |
| f g a b = runWriterT . runExceptT $ do | |
| v <- lift . lift $ g a b | |
| when (length v <= 6) $ throwError "too small!" | |
| tell ["we got this"] | |
| return () | |
| s :: Monad m | |
| => String | |
| -> String | |
| -> m String | |
| s a b = return $ a ++ b | |
| main :: IO () | |
| main = do | |
| let v1 = runIdentity $ f s "holy" "crap" | |
| print v1 | |
| let v2 = runIdentity $ f s "hol" "cra" | |
| print v2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment