Created
December 23, 2016 23:11
-
-
Save relrod/d2ed243c8471a90e7631fa4799826605 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
{-# LANGUAGE FlexibleContexts #-} | |
module SpecializedIO where | |
import Control.Monad.Free | |
data OnlyPrintLine a = OnlyPrintLine String a | |
instance Functor OnlyPrintLine where | |
fmap f (OnlyPrintLine s a) = OnlyPrintLine s (f a) | |
type OnlyPrintLineF = Free OnlyPrintLine | |
-- | OnlyPrintLineF a ~> IO a | |
interpret :: OnlyPrintLineF a -> IO a | |
interpret (Free (OnlyPrintLine s a)) = putStrLn s >> interpret a | |
interpret (Pure a) = return a | |
-- | Pretty interface | |
pp :: MonadFree OnlyPrintLine m => String -> m () | |
pp s = liftF (OnlyPrintLine s ()) | |
main :: OnlyPrintLineF () | |
main = do | |
pp "hello world!" | |
pp "I can't do anything except println now!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment