Skip to content

Instantly share code, notes, and snippets.

@boj
Created February 20, 2019 23:03
Show Gist options
  • Select an option

  • Save boj/519ee61dca1c7e034126ddc6776fd2e0 to your computer and use it in GitHub Desktop.

Select an option

Save boj/519ee61dca1c7e034126ddc6776fd2e0 to your computer and use it in GitHub Desktop.
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