Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main = print . evalCont $ (lazySum <== lazySq <== liftCont product) [[1,2,3],[4,5]]
- data Cont r a = Cont ((a -> r) -> r)
- runCont :: Cont r a -> (a -> r) -> r
- runCont (Cont f) = f
- lazySum :: [[Int]] -> Cont Int [Int]
- lazySum xs = Cont $ \f -> sum $ map f xs
- square x = x * x
- lazySq :: [Int] -> Cont Int [Int]
- lazySq xs = Cont $ \f -> square $ f xs
- contpose :: (a -> Cont r b)
- -> (b -> Cont r c)
- -> (a -> Cont r c)
- contpose c1 c2 ys = Cont $ \f -> (runCont $ c1 ys) (\xs -> runCont (c2 xs) f)
- contFish :: Cont r a -> (a -> Cont r b) -> Cont r b
- contFish c f = (contpose (\_ -> c) f) ()
- contRet :: a -> Cont r a
- contRet x = Cont $ \f -> f x
- liftCont :: (a -> b) -> a -> Cont r b
- liftCont f = \x -> contRet $ f x
- contposeAll (c:[]) = c
- contposeAll (c1:cs) = contpose c1 (contposeAll cs)
- evalCont :: Cont a a -> a
- evalCont c = runCont c id
- (<==) = contpose
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement