Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Control.Arrow
- import Control.Arrow.CoKleisli
- import Control.Comonad
- import Control.Comonad.Reader
- import Data.Array
- import Control.Comonad.Pointer
- import Control.Functor.Extras
- import Data.Monoid
- import Control.Comonad.Exponent
- import Control.Comonad.Stream
- import Control.Functor.Fix
- import Control.Monad.Identity
- import Data.List
- import Control.Comonad.Cofree
- import Control.Comonad.Supply
- ary :: Array Int String
- ary = listArray (0,2) ["hoge", "fuga", "moke"]
- f, g :: Coreader Int Int -> Int
- f x = askC x * extract x
- g x = askC x * 2
- h :: Coreader Int Int -> Coreader Int Int
- h x = x =>> g =>> f
- p0 :: Pointer Int String
- p0 = Pointer 0 ary
- {-
- fact :: Int -> Int
- fact n = runExp $ factSub n $ Exp getProduct
- where
- -}
- factSub :: Int -> Exp [Int] Int -> Int
- factSub 0 acc = extract acc
- factSub n acc = factSub (n-1) (acc =>> (*n) . extract)
- tailS :: Stream a -> Stream a
- tailS st = st =>> extract . runIdentity . outCofree
- streamToList :: Stream a -> [a]
- streamToList = unfoldr phi
- where
- phi st = Just (extract st, tailS st)
- cons :: a -> Stream a -> Stream a
- cons a st = cofree a $ Identity st
- zipWithS :: (a -> b -> c) -> Stream a -> Stream b -> Stream c
- zipWithS g st1 st2 = cons (extract st1 `g` extract st2) $ zipWithS g (tailS st1) (tailS st2)
- zipS :: Stream a -> Stream b -> Stream (a, b)
- zipS = zipWithS (,)
- st1 :: Stream Int
- st1 = cons 1 (st1 =>> (+1) . extract)
- fibs :: Stream Integer
- fibs = cons 1 $ cons 1 $ zipWithS (+) fibs (tailS fibs)
- squareSup :: Num n => Supply n -> Supply n
- squareSup sup = sup =>> \x -> extract x ^ 2
- allSupply :: Supply a -> [a]
- allSupply = map extract . split
Add Comment
Please, Sign In to add comment