packages feed

stream-fusion 0.1 → 0.1.1

raw patch · 3 files changed

+43/−20 lines, 3 files

Files

Data/List/Stream.hs view
@@ -10,14 +10,21 @@ -- -- A reimplementation of the standard Haskell list library to take advantage of -- stream fusion, and new GHC optimisations. The fusion mechanism is--- based on that described in:+-- based on stream fusion for sequences. Described in:  -----      /Rewriting Haskell Strings/, by Duncan Coutts, Don Stewart and+-- *    /Stream Fusion: From Lists to Streams to Nothing at All/, by+--      Duncan Coutts, Roman Leshchinskiy and Don Stwwart, ICFP 2007.+--      <http://www.cse.unsw.edu.au/~dons/papers/CLS07.html>+--+-- *    /Rewriting Haskell Strings/, by Duncan Coutts, Don Stewart and --      Roman Leshchinskiy, Practical Aspects of Declarative Languages --      8th International Symposium, PADL 2007, 2007.--- --      <http://www.cse.unsw.edu.au/~dons/papers/CSL06.html> --+-- See the source for the complete story:+--+-- * <http://www.cse.unsw.edu.au/~dons/code/streams/list/Data/Stream.hs>+-- -- This library is a drop in replacement for "Data.List". -- module Data.List.Stream (@@ -629,9 +636,11 @@ -- | /O(n)/, /fusion/. A strict version of 'foldl'. foldl' :: (a -> b -> a) -> a -> [b] -> a foldl' f z0 xs0 = go z0 xs0+#ifndef __HADDOCK__   where     go !z []     = z     go !z (x:xs) = go (f z x) xs+#endif {-# INLINE [1] foldl' #-}  {-# RULES@@ -662,9 +671,11 @@ foldl1' :: (a -> a -> a) -> [a] -> a foldl1' _ []       = errorEmptyList "foldl1'" foldl1' f (x0:xs0) = go x0 xs0+#ifndef __HADDOCK__   where     go !z []     = z     go !z (x:xs) = go (f z x) xs+#endif {-# INLINE [1] foldl1' #-}  {-# RULES
Data/Stream.hs view
@@ -1,4 +1,3 @@--- #hide {-# OPTIONS_GHC -fdicts-cheap -fbang-patterns #-}  -- |@@ -13,18 +12,24 @@ --  -- Stream fusion for sequences. Described in:  -----      /Rewriting Haskell Strings/, by Duncan Coutts, Don Stewart and+-- *    /Stream Fusion: From Lists to Streams to Nothing at All/, by+--      Duncan Coutts, Roman Leshchinskiy and Don Stwwart, ICFP 2007.+--      <http://www.cse.unsw.edu.au/~dons/papers/CLS07.html>+--+-- *    /Rewriting Haskell Strings/, by Duncan Coutts, Don Stewart and --      Roman Leshchinskiy, Practical Aspects of Declarative Languages --      8th International Symposium, PADL 2007, 2007.+--      <http://www.cse.unsw.edu.au/~dons/papers/CSL06.html> -----      /Stream Fusion: From Lists to Streams to Nothing at All/, by---      Duncan Coutts, Roman Leshchinskiy and Don Stwwart, ICFP 2007.+-- See the source for the complete story: -----      <http://www.cse.unsw.edu.au/~dons/papers/CSL06.html>---      <http://www.cse.unsw.edu.au/~dons/papers/CLS07.html>+-- * <http://www.cse.unsw.edu.au/~dons/code/streams/list/Data/Stream.hs> --+ module Data.Stream ( +#ifndef __HADDOCK__+     -- * The stream data type     Stream(Stream),     Step(..),@@ -225,9 +230,12 @@     bind,                   -- :: (a -> Bool) -> (a -> [b]) -> [a] -> [b]     mapFilter,              -- :: (a -> Bool) -> (a ->  b)  -> [a] -> [b]     declare                 -- :: (a -> Stream b) -> a -> Stream b+#endif    ) where +#ifndef __HADDOCK__+ #ifndef EXTERNAL_PACKAGE  import {-# SOURCE #-} GHC.Err (error)@@ -294,61 +302,63 @@ instance Functor Stream where fmap = map  --- A class of strict unlifted types. The Unlifted constraint in the Stream--- type above enforces a separation between user's types and the types used--- in stream states.+-- | A class of strict unlifted types. The Unlifted constraint in the+-- Stream type above enforces a separation between user's types and the+-- types used in stream states. -- class Unlifted a where -  -- This expose function needs to be called in folds/loops that consume+  -- | This expose function needs to be called in folds/loops that consume   -- streams to expose the structure of the stream state to the simplifier   -- In particular, to SpecConstr.   --   expose :: a -> b -> b   expose = seq -  -- This makes GHC's optimiser happier; it sometimes produces really bad+  -- | This makes GHC's optimiser happier; it sometimes produces really bad   -- code for single-method dictionaries   --   unlifted_dummy :: a   unlifted_dummy = error "unlifted_dummy"  ----- Unlifted versions of () and Bool for use in Stream states.+-- | Unlifted versions of () and Bool for use in Stream states. -- data None   = None instance Unlifted None +-- | A useful unlifted type data Switch = S1 | S2 instance Unlifted Switch --- Unlifted pairs, Maybe and Either+-- | Unlifted pairs, Maybe and Either -- data (Unlifted a, Unlifted b) => a :!: b = !a :!: !b instance (Unlifted a, Unlifted b) => Unlifted (a :!: b) where   expose (a :!: b) s = expose a (expose b s)   {-# INLINE expose #-} +-- | Unlifted Maybes data Unlifted a => Maybe a = Nothing | Just !a instance Unlifted a => Unlifted (Maybe a) where   expose (Just a) s = expose a s   expose  Nothing s =          s   {-# INLINE expose #-} +-- | Unlifted sums data (Unlifted a, Unlifted b) => Either a b = Left !a | Right !b instance (Unlifted a, Unlifted b) => Unlifted (Either a b) where   expose (Left  a) s = expose a s   expose (Right b) s = expose b s   {-# INLINE expose #-} --- Some stream functions (notably concatMap) need to use a stream as a state+-- | Some stream functions (notably concatMap) need to use a stream as a state -- instance Unlifted (Stream a) where   expose (Stream next s0) s = seq next (seq s0 s)   {-# INLINE expose #-} ---- Boxes for user's state. This is the gateway for user's types into unlifted+-- | Boxes for user's state. This is the gateway for user's types into unlifted -- stream states. The L is always safe since it's lifted/lazy, exposing/seqing -- it does nothing. -- S is unlifted and so is only suitable for users states that we know we can@@ -1793,3 +1803,5 @@ moduleError :: String -> String -> a moduleError fun msg = error ("List." ++ fun ++ ':':' ':msg) {-# NOINLINE moduleError #-}++#endif
stream-fusion.cabal view
@@ -1,5 +1,5 @@ Name:                stream-fusion-Version:             0.1+Version:             0.1.1 Author:              Duncan Coutts, Don Stewart Maintainer:          duncan.coutts@worc.ox.ac.uk, dons@galois.com License:             BSD3