Last active
August 29, 2015 14:07
-
-
Save mango314/6f3bd633ee0605217cf2 to your computer and use it in GitHub Desktop.
Having understood categories and monads, we give you...
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
-- http://hackage.haskell.org/package/pipes-text-0.0.0.12/docs/Pipes-Text-IO.html | |
-- http://hackage.haskell.org/package/pipes | |
-- http://hackage.haskell.org/package/pipes-text | |
import Pipes | |
import qualified Pipes.Text as Text | |
import qualified Pipes.Text.IO as Text | |
import System.IO | |
-- http://stackoverflow.com/questions/19521246/what-does-mean-do-in-haskell | |
main = | |
withFile "hello.txt" ReadMode $ \hIn -> | |
withFile "world.txt" WriteMode $ \hOut -> | |
runEffect $ Text.fromHandle hIn >-> mydo >-> Text.toHandle hOut | |
where mydo = for cat $ \x -> yield x |
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
*Main> :t runEffect | |
runEffect :: Monad m => Effect m r -> m r | |
*Main> :i Effect | |
type Effect = Proxy X () () X -- Defined in `Pipes.Core' | |
-- Learn about Monad and Proxy... | |
*Main> :i Proxy | |
data Proxy a' a b' b m r | |
= Pipes.Internal.Request a' (a -> Proxy a' a b' b m r) | |
| Pipes.Internal.Respond b (b' -> Proxy a' a b' b m r) | |
| Pipes.Internal.M (m (Proxy a' a b' b m r)) | |
| Pipes.Internal.Pure r | |
-- Defined in `Pipes.Internal' | |
instance Monad m => Monad (Proxy a' a b' b m) | |
-- Defined in `Pipes.Internal' | |
instance Monad m => Functor (Proxy a' a b' b m) | |
-- Defined in `Pipes.Internal' | |
instance MonadPlus m => MonadPlus (Proxy a' a b' b m) | |
-- Defined in `Pipes.Internal' | |
instance Monad m => Applicative (Proxy a' a b' b m) | |
-- Defined in `Pipes.Internal' | |
instance MonadTrans (Proxy a' a b' b) | |
-- Defined in `Pipes.Internal' | |
instance MonadIO m => MonadIO (Proxy a' a b' b m) | |
-- Defined in `Pipes.Internal' | |
instance MFunctor (Proxy a' a b' b) -- Defined in `Pipes.Internal' | |
*Main> :i Monad | |
class Monad m where | |
(>>=) :: m a -> (a -> m b) -> m b | |
(>>) :: m a -> m b -> m b | |
return :: a -> m a | |
fail :: String -> m a | |
-- Defined in `GHC.Base' | |
instance Monad Identity -- Defined in `Data.Functor.Identity' | |
instance Monad m => Monad (Proxy a' a b' b m) | |
-- Defined in `Pipes.Internal' | |
instance Monad (Either e) -- Defined in `Data.Either' | |
instance Monad Maybe -- Defined in `Data.Maybe' | |
instance Monad m => Monad (ListT m) -- Defined in `Pipes' | |
instance Monad [] -- Defined in `GHC.Base' | |
instance Monad IO -- Defined in `GHC.Base' | |
instance Monad ((->) r) -- Defined in `GHC.Base' | |
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
*Main> :t withFile | |
withFile :: FilePath -> IOMode -> (Handle -> IO r) -> IO r | |
*Main> :i FilePath | |
type FilePath = String -- Defined in `GHC.IO' | |
*Main> :i IOMode | |
data IOMode = ReadMode | WriteMode | AppendMode | ReadWriteMode | |
-- Defined in `GHC.IO.IOMode' | |
instance Enum IOMode -- Defined in `GHC.IO.IOMode' | |
instance Eq IOMode -- Defined in `GHC.IO.IOMode' | |
instance Ord IOMode -- Defined in `GHC.IO.IOMode' | |
instance Read IOMode -- Defined in `GHC.IO.IOMode' | |
instance Show IOMode -- Defined in `GHC.IO.IOMode' | |
*Main> :i Handle | |
data Handle | |
= GHC.IO.Handle.Types.FileHandle FilePath | |
{-# UNPACK #-} !(GHC.MVar.MVar GHC.IO.Handle.Types.Handle__) | |
| GHC.IO.Handle.Types.DuplexHandle FilePath | |
{-# UNPACK #-} !(GHC.MVar.MVar GHC.IO.Handle.Types.Handle__) | |
{-# UNPACK #-} !(GHC.MVar.MVar GHC.IO.Handle.Types.Handle__) | |
-- Defined in `GHC.IO.Handle.Types' | |
instance Eq Handle -- Defined in `GHC.IO.Handle.Types' | |
instance Show Handle -- Defined in `GHC.IO.Handle.Types' | |
*Main> :i IO | |
newtype IO a | |
= GHC.Types.IO (GHC.Prim.State# GHC.Prim.RealWorld | |
-> (# GHC.Prim.State# GHC.Prim.RealWorld, a #)) | |
-- Defined in `GHC.Types' | |
instance Monad IO -- Defined in `GHC.Base' | |
instance Functor IO -- Defined in `GHC.Base' | |
instance MonadPlus IO -- Defined in `Control.Monad.Trans.Error' | |
instance Applicative IO -- Defined in `Control.Applicative' | |
instance MonadIO IO -- Defined in `Control.Monad.IO.Class' |
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
*Main> :i IOMode | |
data IOMode = ReadMode | WriteMode | AppendMode | ReadWriteMode | |
-- Defined in `GHC.IO.IOMode' | |
instance Enum IOMode -- Defined in `GHC.IO.IOMode' | |
instance Eq IOMode -- Defined in `GHC.IO.IOMode' | |
instance Ord IOMode -- Defined in `GHC.IO.IOMode' | |
instance Read IOMode -- Defined in `GHC.IO.IOMode' | |
instance Show IOMode -- Defined in `GHC.IO.IOMode' | |
*Main> :i ReadMode | |
data IOMode = ReadMode | ... -- Defined in `GHC.IO.IOMode' | |
*Main> :i WriteMode | |
data IOMode = ... | WriteMode | ... -- Defined in `GHC.IO.IOMode' |
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
-- Haskell doesn't have "for" loops and yet | |
*Main> :i for | |
for :: | |
Monad m => | |
Proxy x' x b' b m a' | |
-> (b -> Proxy x' x c' c m b') -> Proxy x' x c' c m a' | |
-- Defined in `Pipes' |
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
Hello World! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment