{-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} module Cascade.Examples where import Cascade import Cascade.Debugger import Control.Category import Control.Monad import Data.Char (toUpper) import Prelude hiding (id, (.)) import System.Environment (getEnv, setEnv, getProgName) -- example funcitonal cascades fc, gc :: Cascade '[String, Int, Double, Double] fc = read :>>> fromIntegral :>>> (1/) :>>> Done gc = length :>>> (2^) :>>> negate :>>> Done -- some example monadic cascades mc, nc :: CascadeM IO '[ String, (), String, String, () ] mc = putStr >=>: const getLine >=>: return . map toUpper >=>: putStrLn >=>: Done nc = setEnv "foo" >=>: const (return "foo") >=>: getEnv >=>: print . length >=>: Done -- some example comonadic cascades wc, vc :: CascadeW ((,) Char) '[ Int, Char, Int, String ] wc = fst =>=: fromEnum . snd =>=: uncurry (flip replicate) =>=: Done vc = toEnum . snd =>=: const 5 =>=: show =>=: Done -- run the debugger for the mc cascade all the way to the end rundmc :: IO (DebuggerM IO '[String, String, (), [Char]] () '[]) rundmc = debugM >>> use "walk this way\n> " >=> step >=> step >=> step $ mc -- alternate using functions from one cascade then the other zigzag :: CascadeC c ts -> CascadeC c ts -> CascadeC c ts zigzag Done Done = Done zigzag (f :>>> fc) (_ :>>> gc) = f :>>> zigzag gc fc