diff --git a/src/Scat.hs b/src/Scat.hs index 0d13eaa..955216c 100644 --- a/src/Scat.hs +++ b/src/Scat.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE OverloadedStrings, PatternGuards #-} +{-# LANGUAGE OverloadedStrings #-} -- | Password scatterer. module Main (main) where @@ -148,7 +148,7 @@ getCode = do else return "" --- | Lists all the available schemas. +-- | Lists all the available schemas. schemas :: [(String, Scat Schema)] schemas = [ ("safe", return safe) diff --git a/src/Scat/Builder.hs b/src/Scat/Builder.hs index 94daad1..49caa25 100644 --- a/src/Scat/Builder.hs +++ b/src/Scat/Builder.hs @@ -63,7 +63,7 @@ instance Applicative Builder where pure x = Builder (\ n -> (n, x)) f <*> x = Builder $ \ n -> let (n', g) = runBuilder f n - in fmap g $ runBuilder x n' + in g <$> runBuilder x n' instance Monad Builder where return = pure @@ -85,19 +85,19 @@ inRange (a, b) = fmap (+ a) $ lessThan $ b + 1 - a -- | Returns a lower case letter. lower :: Builder Char -lower = fmap (chr . (+ ord 'a')) $ lessThan 26 +lower = (chr . (+ ord 'a')) <$> lessThan 26 -- | Returns an upper case letter. upper :: Builder Char -upper = fmap (chr . (+ ord 'A')) $ lessThan 26 +upper = (chr . (+ ord 'A')) <$> lessThan 26 -- | Returns an printable ascii char. ascii :: Builder Char -ascii = fmap chr $ inRange (32, 126) +ascii = chr <$> inRange (32, 126) -- | Returns a digit. digit :: Builder Char -digit = fmap chr $ inRange (48, 57) +digit = chr <$> inRange (48, 57) -- | Returns a letter. letter :: Builder Char diff --git a/src/Scat/Schemas.hs b/src/Scat/Schemas.hs index 92b2248..4cb129c 100644 --- a/src/Scat/Schemas.hs +++ b/src/Scat/Schemas.hs @@ -15,6 +15,7 @@ module Scat.Schemas , getBuilder -- * Built-in schemas + -- ** Passwords , safe , alphanumeric @@ -36,6 +37,7 @@ import Data.List (intercalate, (\\)) import Data.Vector (Vector) import qualified Data.Vector as V import Data.Monoid +import Control.Applicative import Control.Monad (replicateM) import System.IO @@ -165,7 +167,7 @@ androidPatternLock = withDefaultSize 9 $ \ s -> do {- | Generates a password with `s` of the original Pokemons and their level. Entropy of about 55.5 bits for 4 pokemons. -} pokemons :: IO Schema -pokemons = fromFile "pokemons.txt" $ \ vect -> +pokemons = fromFile "pokemons.txt" $ \ vect -> withDefaultSize 4 $ \ s -> do ps <- replicateM s $ oneOfV vect ls <- replicateM s $ inRange (1, 100 :: Int) @@ -186,5 +188,5 @@ fromFile :: FilePath -> (Vector String -> a) -> IO a fromFile fp bs = do fp' <- getDataFileName fp withFile fp' ReadMode $ \ h -> do - !vect <- fmap (V.fromList . lines) $ hGetContents h + !vect <- (V.fromList . lines) <$> hGetContents h return $ bs vect