on master help sign in
Enumerator is now a type synonym
commit8618fead80bff0e4c7598bff9df890c36e387693 authorMichael Snoyman <michael@snoyman.com> dateThu 28 Jan 2010, 17:23 (17 years ago) parent644bfda
3 files changed+8−11
Network/Wai.hs+3−4 Network/Wai/Handler/SimpleServer.hs+2−3 test.hs+3−4
Network/Wai.hs+3−4
@@ -24,7 +24,7 @@ module Network.Wai
2424 , statusCode
2525 , statusMessage
2626 -- * Enumerator
27− , Enumerator (..)
27+ , Enumerator
2828 -- * WAI interface
2929 , Request (..)
3030 , Response (..)
@@ -235,8 +235,7 @@ statusMessage Status405 = B8.pack "Method Not Allowed"
235235statusMessage Status500 = B8.pack "Internal Server Error"
236236statusMessage (Status _ m) = m
237237
238−data Enumerator = Enumerator (forall a.
239− ((a -> B.ByteString -> IO (Either a a)) -> a -> IO a))
238+type Enumerator a = (a -> B.ByteString -> IO (Either a a)) -> a -> IO a
240239
241240data Request = Request
242241 { requestMethod :: Method
@@ -255,7 +254,7 @@ data Request = Request
255254data Response = Response
256255 { status :: Status
257256 , headers :: [(ResponseHeader, B.ByteString)]
258− , body :: Either FilePath Enumerator
257+ , body :: forall a. Either FilePath (Enumerator a)
259258 }
260259
261260type Application = Request -> IO Response
Network/Wai/Handler/SimpleServer.hs+2−3
@@ -21,7 +21,6 @@ import Network.Wai
2121import qualified System.IO
2222
2323import qualified Data.ByteString as BS
24−import qualified Data.ByteString.Lazy as BL
2524import qualified Data.ByteString.Char8 as B8
2625import Network
2726 ( listenOn, accept, sClose, PortID(PortNumber), Socket
@@ -167,9 +166,9 @@ sendResponse h res = do
167166 BS.hPut h $ SL.pack "\r\n"
168167 case body res of
169168 Left fp -> unsafeSendFile h fp
170− Right (Enumerator enum) -> enum myPut h >> return ()
169+ Right enum -> enum myPut h >> return ()
171170 where
172− myPut h bs = BS.hPut h bs >> return (Right h)
171+ myPut _ bs = BS.hPut h bs >> return (Right h)
173172 putHeader (x, y) = do
174173 BS.hPut h $ responseHeaderToBS x
175174 BS.hPut h $ SL.pack ": "
test.hs+3−4
@@ -28,9 +28,8 @@ postResponse rb = return Response
2828index :: Either FilePath a
2929index = Left "index.html"
3030
31−postBody :: IO (Maybe B.ByteString) -> Enumerator
32−postBody req = Enumerator $ \f a -> helper f a where
33− helper f a = do
31+postBody :: IO (Maybe B.ByteString) -> Enumerator a
32+postBody req f a = do
3433 mbs <- req
3534 case mbs of
3635 Nothing -> return a
@@ -38,4 +37,4 @@ postBody req = Enumerator $ \f a -> helper f a where
3837 res <- f a bs
3938 case res of
4039 Left a' -> return a'
41− Right a' -> helper f a'
40+ Right a' -> postBody req f a'