packages feed

handle-like 0.0.0.10 → 0.0.0.11

raw patch · 4 files changed

+70/−54 lines, 4 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Data.HandleLike: instance HandleLike Handle
+ Data.HandleLike.Class: class (Monad (HandleMonad h), Num (DebugLevel h)) => HandleLike h where type family HandleMonad h type family DebugLevel h type instance DebugLevel h = Int hlGetByte h = do { [b] <- unpack `liftM` hlGet h 1; return b } hlGetLine h = do { b <- hlGetByte h; case b of { 10 -> return "" _ -> cons b `liftM` hlGetLine h } } hlGetContent = flip hlGet 1 hlFlush _ = return () hlDebug _ _ _ = return () hlError _ msg = error $ unpack msg
+ Data.HandleLike.Class: hlClose :: HandleLike h => h -> HandleMonad h ()
+ Data.HandleLike.Class: hlDebug :: HandleLike h => h -> DebugLevel h -> ByteString -> HandleMonad h ()
+ Data.HandleLike.Class: hlError :: HandleLike h => h -> ByteString -> HandleMonad h a
+ Data.HandleLike.Class: hlFlush :: HandleLike h => h -> HandleMonad h ()
+ Data.HandleLike.Class: hlGet :: HandleLike h => h -> Int -> HandleMonad h ByteString
+ Data.HandleLike.Class: hlGetByte :: HandleLike h => h -> HandleMonad h Word8
+ Data.HandleLike.Class: hlGetContent :: HandleLike h => h -> HandleMonad h ByteString
+ Data.HandleLike.Class: hlGetLine :: HandleLike h => h -> HandleMonad h ByteString
+ Data.HandleLike.Class: hlPut :: HandleLike h => h -> ByteString -> HandleMonad h ()
+ Data.HandleLike.Class: hlPutStrLn :: HandleLike h => h -> ByteString -> HandleMonad h ()
+ Data.HandleLike.Instance.Handle: instance HandleLike Handle

Files

handle-like.cabal view
@@ -2,7 +2,7 @@ build-type:	Simple  name:		handle-like-version:	0.0.0.10+version:	0.0.0.11 stability:	Experimental author:		Yoshikuni Jujo <PAF01143@nifty.ne.jp> maintainer:	Yoshikuni Jujo <PAF01143@nifty.ne.jp>@@ -38,10 +38,11 @@ source-repository	this     type:	git     location:	git://github.com/YoshikuniJujo/forest-    tag:	handle-like-0.0.0.10+    tag:	handle-like-0.0.0.11  library     hs-source-dirs:	src-    exposed-modules:	Data.HandleLike+    exposed-modules:+        Data.HandleLike, Data.HandleLike.Class, Data.HandleLike.Instance.Handle     build-depends:	base == 4.*, bytestring == 0.10.*     ghc-options:	-Wall
src/Data/HandleLike.hs view
@@ -2,54 +2,5 @@  module Data.HandleLike (HandleLike(..), hlPutStrLn) where -import Control.Monad-import Data.Word-import qualified Data.ByteString as BS-import qualified Data.ByteString.Char8 as BSC-import System.IO--class (Monad (HandleMonad h), Num (DebugLevel h)) =>-	HandleLike h where-	type HandleMonad h-	type DebugLevel h-	hlPut :: h -> BS.ByteString -> HandleMonad h ()-	hlGet :: h -> Int -> HandleMonad h BS.ByteString-	hlGetByte :: h -> HandleMonad h Word8-	hlGetLine :: h -> HandleMonad h BS.ByteString-	hlGetContent :: h -> HandleMonad h BS.ByteString-	hlFlush :: h -> HandleMonad h ()-	hlClose :: h -> HandleMonad h ()-	hlDebug :: h -> DebugLevel h -> BS.ByteString -> HandleMonad h ()-	hlError :: h -> BS.ByteString -> HandleMonad h a--	type DebugLevel h = Int-	hlGetByte h = do [b] <- BS.unpack `liftM` hlGet h 1; return b-	hlGetLine h = do-		b <- hlGetByte h-		case b of-			10 -> return ""-			_ -> BS.cons b `liftM` hlGetLine h-	hlGetContent = flip hlGet 1-	hlFlush _ = return ()-	hlDebug _ _ _ = return ()-	hlError _ msg = error $ BSC.unpack msg--instance HandleLike Handle where-	type HandleMonad Handle = IO-	hlPut = BS.hPut-	hlGet = BS.hGet---	hlGetByte h = do [b] <- BS.unpack <$> BS.hGet h 1; return b-	hlGetLine = (chopCR `liftM`) . BS.hGetLine---	hlGetContent = flip BS.hGet 1-	hlDebug _ _ = BS.hPutStr stderr-	hlFlush = hFlush-	hlClose = hClose--hlPutStrLn :: HandleLike h => h -> BS.ByteString -> HandleMonad h ()-hlPutStrLn h = hlPut h . (`BS.append` "\n")--chopCR :: BS.ByteString -> BS.ByteString-chopCR bs-	| BS.null bs = ""-	| BSC.last bs == '\r' = BSC.init bs-	| otherwise = bs+import Data.HandleLike.Class+import Data.HandleLike.Instance.Handle ()
+ src/Data/HandleLike/Class.hs view
@@ -0,0 +1,37 @@+{-# LANGUAGE OverloadedStrings, TypeFamilies, FlexibleContexts #-}++module Data.HandleLike.Class (HandleLike(..), hlPutStrLn) where++import Control.Monad+import Data.Word+import qualified Data.ByteString as BS+import qualified Data.ByteString.Char8 as BSC++class (Monad (HandleMonad h), Num (DebugLevel h)) =>+	HandleLike h where+	type HandleMonad h+	type DebugLevel h+	hlPut :: h -> BS.ByteString -> HandleMonad h ()+	hlGet :: h -> Int -> HandleMonad h BS.ByteString+	hlGetByte :: h -> HandleMonad h Word8+	hlGetLine :: h -> HandleMonad h BS.ByteString+	hlGetContent :: h -> HandleMonad h BS.ByteString+	hlFlush :: h -> HandleMonad h ()+	hlClose :: h -> HandleMonad h ()+	hlDebug :: h -> DebugLevel h -> BS.ByteString -> HandleMonad h ()+	hlError :: h -> BS.ByteString -> HandleMonad h a++	type DebugLevel h = Int+	hlGetByte h = do [b] <- BS.unpack `liftM` hlGet h 1; return b+	hlGetLine h = do+		b <- hlGetByte h+		case b of+			10 -> return ""+			_ -> BS.cons b `liftM` hlGetLine h+	hlGetContent = flip hlGet 1+	hlFlush _ = return ()+	hlDebug _ _ _ = return ()+	hlError _ msg = error $ BSC.unpack msg++hlPutStrLn :: HandleLike h => h -> BS.ByteString -> HandleMonad h ()+hlPutStrLn h = hlPut h . (`BS.append` "\n")
+ src/Data/HandleLike/Instance/Handle.hs view
@@ -0,0 +1,27 @@+{-# LANGUAGE OverloadedStrings, TypeFamilies, FlexibleContexts #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}++module Data.HandleLike.Instance.Handle () where++import Control.Monad+import qualified Data.ByteString as BS+import qualified Data.ByteString.Char8 as BSC+import System.IO+import Data.HandleLike.Class++instance HandleLike Handle where+	type HandleMonad Handle = IO+	hlPut = BS.hPut+	hlGet = BS.hGet+--	hlGetByte h = do [b] <- BS.unpack <$> BS.hGet h 1; return b+	hlGetLine = (chopCR `liftM`) . BS.hGetLine+--	hlGetContent = flip BS.hGet 1+	hlDebug _ _ = BS.hPutStr stderr+	hlFlush = hFlush+	hlClose = hClose++chopCR :: BS.ByteString -> BS.ByteString+chopCR bs+	| BS.null bs = ""+	| BSC.last bs == '\r' = BSC.init bs+	| otherwise = bs