remove read of the heads
and one tail Removed head from Utility.PartialPrelude in order to avoid the build warning with recent ghc versions as well.
This commit is contained in:
parent
10216b44d2
commit
4ca3d1d584
12 changed files with 32 additions and 42 deletions
|
@ -180,16 +180,16 @@ compareSizes units abbrev old new
|
|||
|
||||
{- Parses strings like "10 kilobytes" or "0.5tb". -}
|
||||
readSize :: [Unit] -> String -> Maybe ByteSize
|
||||
readSize units input
|
||||
| null parsednum || null parsedunit = Nothing
|
||||
| otherwise = Just $ round $ number * fromIntegral multiplier
|
||||
readSize units input = case parsednum of
|
||||
[] -> Nothing
|
||||
((number, rest):_) ->
|
||||
let unitname = takeWhile isAlpha $ dropWhile isSpace rest
|
||||
in case lookupUnit units unitname of
|
||||
[] -> Nothing
|
||||
(multiplier:_) ->
|
||||
Just $ round $ number * fromIntegral multiplier
|
||||
where
|
||||
(number, rest) = head parsednum
|
||||
multiplier = head parsedunit
|
||||
unitname = takeWhile isAlpha $ dropWhile isSpace rest
|
||||
|
||||
parsednum = reads input :: [(Double, String)]
|
||||
parsedunit = lookupUnit units unitname
|
||||
|
||||
lookupUnit _ [] = [1] -- no unit given, assume bytes
|
||||
lookupUnit [] _ = []
|
||||
|
|
|
@ -52,9 +52,8 @@ readFileStrict = readFile >=> \s -> length s `seq` return s
|
|||
separate :: (a -> Bool) -> [a] -> ([a], [a])
|
||||
separate c l = unbreak $ break c l
|
||||
where
|
||||
unbreak r@(a, b)
|
||||
| null b = r
|
||||
| otherwise = (a, tail b)
|
||||
unbreak (a, (_:b)) = (a, b)
|
||||
unbreak r = r
|
||||
|
||||
separate' :: (Word8 -> Bool) -> S.ByteString -> (S.ByteString, S.ByteString)
|
||||
separate' c l = unbreak $ S.break c l
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
|
||||
module Utility.PartialPrelude (
|
||||
Utility.PartialPrelude.read,
|
||||
Utility.PartialPrelude.head,
|
||||
Utility.PartialPrelude.tail,
|
||||
Utility.PartialPrelude.init,
|
||||
Utility.PartialPrelude.last,
|
||||
Utility.PartialPrelude.readish,
|
||||
|
@ -27,16 +25,6 @@ import qualified Data.Maybe
|
|||
read :: Read a => String -> a
|
||||
read = Prelude.read
|
||||
|
||||
{- head is a partial function; head [] is an error
|
||||
- Instead, use: take 1 or headMaybe -}
|
||||
head :: [a] -> a
|
||||
head = Prelude.head
|
||||
|
||||
{- tail is also partial
|
||||
- Instead, use: drop 1 -}
|
||||
tail :: [a] -> [a]
|
||||
tail = Prelude.tail
|
||||
|
||||
{- init too
|
||||
- Instead, use: beginning -}
|
||||
init :: [a] -> [a]
|
||||
|
|
|
@ -80,7 +80,7 @@ addHiddenService appname uid ident = do
|
|||
((p, _s):_) -> waithiddenservice 1 p
|
||||
_ -> do
|
||||
highports <- R.getStdRandom mkhighports
|
||||
let newport = Prelude.head $
|
||||
let newport = fromMaybe (error "internal") $ headMaybe $
|
||||
filter (`notElem` map fst portssocks) highports
|
||||
torrc <- findTorrc
|
||||
writeFile torrc $ unlines $
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue