oi 0.0.1 → 0.0.2
raw patch · 3 files changed
+27/−2 lines, 3 files
Files
- oi.cabal +1/−1
- sample/echo.hs +3/−0
- src/Data/OI.hs +23/−1
oi.cabal view
@@ -1,5 +1,5 @@ Name: oi-Version: 0.0.1+Version: 0.0.2 Category: Data Synopsis: Purely Functional Lazy Interaction with the outer world Description: This package implements a data structure and operations on it
sample/echo.hs view
@@ -31,3 +31,6 @@ getchar :: IO Int getchar = choice (return (-1)) (return . ord =<< getChar) =<< isEOF ++puts' :: String -> [()] :-> ()+puts' = sequenceOI . map putc
src/Data/OI.hs view
@@ -20,9 +20,12 @@ ,deTuple ,deList ,(<|)+ ,mapOI+ ,mapOI' ,zipWithOI ,zipWithOI'- ,mapOI+ ,sequenceOI+ ,sequenceOI' ) where import Control.Applicative@@ -100,6 +103,7 @@ io = (:) <$> (unsafeInterleaveIO (dereference vx)) <*> (unsafeInterleaveIO (dereference vxs)) --+infixr 1 <| (<|) :: (b -> c :-> d) -> (a :-> b) -> (a,c) :-> d (f <| g) ac = case deTuple ac of (a,c) -> f (g a) c@@ -109,6 +113,12 @@ Just (x,xs) -> f x : mapOI f xs _ -> [] +mapOI' :: (a :-> b) -> [a] :-> (OI [a],[b])+mapOI' f xxs = case deList xxs of+ Just (x,xs) -> (zs, f x:ys)+ where (zs,ys) = mapOI' f xs+ _ -> (xxs,[])+ zipWithOI :: (a -> b :-> c) -> [a] -> [b] :-> [c] zipWithOI _ [] _ = [] zipWithOI f (x:xs) yys = case deList yys of@@ -120,6 +130,18 @@ zipWithOI' f (x:xs) yys = case deList yys of Just (y,ys) -> case zipWithOI' f xs ys of ~(rs,zs) -> (rs,f x y : zs) _ -> (yys,[])++sequenceOI :: [a :-> b] -> [a] :-> ()+sequenceOI (f:fs) xxs = case deList xxs of+ Just (x,xs) -> f x `pseq` sequenceOI fs xs+ Nothing -> ()+sequenceOI [] _ = ()++sequenceOI' :: [a :-> b] -> [a] :-> OI [a]+sequenceOI' (f:fs) xxs = case deList xxs of+ Just (x,xs) -> f x `pseq` sequenceOI' fs xs+ Nothing -> xxs+sequenceOI' [] xxs = xxs --