Guest User

Untitled

a guest
Apr 20th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Prelude hiding((.), id)
  2. import Control.Arrow        
  3. import Control.Category
  4.  
  5. newtype Stream a b = Stream { runStream :: [a] -> [b] }      
  6.  
  7. instance Category Stream where
  8.   id = Stream (id)
  9.   (.) (Stream (f)) (Stream (g)) = Stream (f . g)
  10.  
  11. instance Arrow Stream where
  12.   arr f = Stream (map f)
  13.   first (Stream f) = Stream (unzip >>> first f >>> uncurry zip)
  14.  
  15. instance ArrowLoop Stream where
  16.   loop (Stream f) = Stream $ \iL ->
  17.     let (oL,sL) = unzip $ f $ zip iL sL in
  18.     oL
  19.  
  20. delay x = Stream (x:)
  21.  
  22. stream ~(x:xs) = x:stream xs
  23.  
  24. mul = arr (uncurry (*))
  25.  
  26. facStream = loop (mul >>> (arr id &&& delay 1))
Add Comment
Please, Sign In to add comment