packages feed

handle-like 0.0.0.13 → 0.0.0.14

raw patch · 4 files changed

+68/−86 lines, 4 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Data.HandleLike.Class: Critical :: Priority
- Data.HandleLike.Class: High :: Priority
- Data.HandleLike.Class: Low :: Priority
- Data.HandleLike.Class: Moderate :: Priority
- Data.HandleLike.Class: class (Monad (HandleMonad h), IsString (DebugLevel h), Ord (DebugLevel h)) => HandleLike h where type family HandleMonad h type family DebugLevel h type instance DebugLevel h = Priority 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: data Priority
- 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.Class: instance Enum Priority
- Data.HandleLike.Class: instance Eq Priority
- Data.HandleLike.Class: instance IsString Priority
- Data.HandleLike.Class: instance Ord Priority
- Data.HandleLike.Class: instance Read Priority
- Data.HandleLike.Class: instance Show Priority
- Data.HandleLike.Instance.Handle: instance HandleLike Handle
+ Data.HandleLike: instance Enum Priority
+ Data.HandleLike: instance Eq Priority
+ Data.HandleLike: instance HandleLike Handle
+ Data.HandleLike: instance IsString Priority
+ Data.HandleLike: instance Ord Priority
+ Data.HandleLike: instance Read Priority
+ Data.HandleLike: instance Show Priority

Files

handle-like.cabal view
@@ -2,7 +2,7 @@ build-type:	Simple  name:		handle-like-version:	0.0.0.13+version:	0.0.0.14 stability:	Experimental author:		Yoshikuni Jujo <PAF01143@nifty.ne.jp> maintainer:	Yoshikuni Jujo <PAF01143@nifty.ne.jp>@@ -38,11 +38,10 @@ source-repository	this     type:	git     location:	git://github.com/YoshikuniJujo/forest-    tag:	handle-like-0.0.0.13+    tag:	handle-like-0.0.0.14  library     hs-source-dirs:	src-    exposed-modules:-        Data.HandleLike, Data.HandleLike.Class, Data.HandleLike.Instance.Handle+    exposed-modules: Data.HandleLike     build-depends:	base == 4.*, bytestring == 0.10.*     ghc-options:	-Wall
src/Data/HandleLike.hs view
@@ -2,5 +2,68 @@  module Data.HandleLike (HandleLike(..), hlPutStrLn) where -import Data.HandleLike.Class-import Data.HandleLike.Instance.Handle ()+import Control.Monad+import Data.Word+import qualified Data.ByteString as BS+import qualified Data.ByteString.Char8 as BSC+import Data.String++import System.IO++class (Monad (HandleMonad h),+	IsString (DebugLevel h), Ord (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 = Priority+	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")++data Priority = Low | Moderate | High | Critical+	deriving (Show, Read, Eq, Ord, Enum)++instance IsString Priority where+	fromString s = case takeWhile (/= ':') s of+		"low" -> Low+		"high" -> High+		"critical" -> Critical+		_ -> Moderate++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 _ Critical = BS.hPutStr stderr+	hlDebug _ _ = const $ return ()+	hlFlush = hFlush+	hlClose = hClose++chopCR :: BS.ByteString -> BS.ByteString+chopCR bs+	| BS.null bs = ""+	| BSC.last bs == '\r' = BSC.init bs+	| otherwise = bs
− src/Data/HandleLike/Class.hs
@@ -1,52 +0,0 @@-{-# LANGUAGE OverloadedStrings, TypeFamilies, FlexibleContexts #-}--module Data.HandleLike.Class (-	HandleLike(..),-	Priority(..),-	hlPutStrLn ) where--import Control.Monad-import Data.Word-import qualified Data.ByteString as BS-import qualified Data.ByteString.Char8 as BSC-import Data.String--class (Monad (HandleMonad h),-	IsString (DebugLevel h), Ord (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 = Priority-	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")--data Priority = Low | Moderate | High | Critical-	deriving (Show, Read, Eq, Ord, Enum)--instance IsString Priority where-	fromString s = case takeWhile (/= ':') s of-		"low" -> Low-		"high" -> High-		"critical" -> Critical-		_ -> Moderate
− src/Data/HandleLike/Instance/Handle.hs
@@ -1,28 +0,0 @@-{-# 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 _ Low = const $ return ()-	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