Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. {-# LANGUAGE DataKinds #-}
  2. {-# LANGUAGE FlexibleContexts #-}
  3. {-# LANGUAGE GADTs #-}
  4. {-# LANGUAGE LambdaCase #-}
  5. {-# LANGUAGE PolyKinds #-}
  6. {-# LANGUAGE RankNTypes #-}
  7. {-# LANGUAGE ScopedTypeVariables #-}
  8. {-# LANGUAGE TemplateHaskell #-}
  9. {-# LANGUAGE TypeApplications #-}
  10. {-# LANGUAGE TypeFamilies #-}
  11. {-# LANGUAGE TypeOperators #-}
  12.  
  13. module Main where
  14.  
  15. import Polysemy
  16.  
  17. data Console m a where
  18. ReadTTY :: Console m Text
  19. WriteTTY :: Text -> Console m ()
  20.  
  21. makeSem ''Console
  22.  
  23. runConsoleIO :: (Member (Lift IO) r) => Sem (Console ': r) a -> Sem r a
  24. runConsoleIO = interpret $ \case
  25. ReadTTY -> sendM getLine
  26. WriteTTY msg -> sendM $ putTextLn msg
  27.  
  28. main :: IO ()
  29. main = runConsoleIO $ do
  30. input <- readTTY
  31. writeTTY input
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement