From 696c74e4088303f0b6da7c1537f6400849cb7f3e Mon Sep 17 00:00:00 2001 From: Michele Guerini Rocco Date: Fri, 12 Dec 2014 22:19:42 +0100 Subject: [PATCH 1/4] Update to reflect new syntax --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ff6339..461a83e 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Example usage: $ alea doso epurai usci selve dirupo bs - $ alea --phrases 3 --phraselength 8 + $ alea -p 3 -l 8 sturai sapone ripeto leghi osasse fori terme oserai carta getto osiamo banale figura smilzi celibe gigli porvi rs traini dotati aureo solito malato gelate From 73093e4e29e783bd53627c4eeae9a782d172ae76 Mon Sep 17 00:00:00 2001 From: Michele Guerini Rocco Date: Sat, 13 Dec 2014 01:03:43 +0100 Subject: [PATCH 2/4] Fix whitespace mess --- main.hs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/main.hs b/main.hs index 21b9f0c..6024b4c 100644 --- a/main.hs +++ b/main.hs @@ -10,11 +10,11 @@ import Alea.Diceware import Alea.Random data ProgArgs = ProgArgs - { interactive :: Bool - , dictionary :: FilePath - , phraseLength :: Int - , phrases :: Int - } deriving (Show) + { interactive :: Bool + , dictionary :: FilePath + , phraseLength :: Int + , phrases :: Int + } deriving (Show) parser :: IO (ParserSpec ProgArgs) parser = path >>= \path -> return $ ProgArgs @@ -44,12 +44,12 @@ readDict args@ProgArgs{..} = -- Main function exec :: ProgArgs -> IO () exec args@ProgArgs{..} = - if interactive - then interact (unlines . map dice . lines) - else do - randWords dictSize phraseLength >>= putStrLn . unwords . map dice' - when (phrases > 1) $ exec args {phrases = phrases - 1} - where - (dict, dictSize) = (parseDiceware dictionary, length dict) - dice n = readDiceware dict (read n :: Int) - dice' n = readDiceware' dict n \ No newline at end of file + if interactive + then interact (unlines . map dice . lines) + else do + randWords dictSize phraseLength >>= putStrLn . unwords . map dice' + when (phrases > 1) $ exec args {phrases = phrases - 1} + where + (dict, dictSize) = (parseDiceware dictionary, length dict) + dice n = readDiceware dict (read n :: Int) + dice' n = readDiceware' dict n From 7ec9fbe88458d4fc3713208ab2bc97438f31ebec Mon Sep 17 00:00:00 2001 From: Michele Guerini Rocco Date: Sat, 13 Dec 2014 01:05:02 +0100 Subject: [PATCH 3/4] Fix whitespace --- Alea/List.hs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Alea/List.hs b/Alea/List.hs index 844f63f..f1c35dd 100644 --- a/Alea/List.hs +++ b/Alea/List.hs @@ -5,7 +5,6 @@ module Alea.List where split :: (Eq a) => a -> [a] -> [[a]] split _ [] = [[]] split delim (c:cs) - | c == delim = [] : rest - | otherwise = (c : head rest) : tail rest - where - rest = split delim cs + | c == delim = [] : rest + | otherwise = (c : head rest) : tail rest + where rest = split delim cs From 366bce49a6948be3739739d712592e3915fd18ae Mon Sep 17 00:00:00 2001 From: Michele Guerini Rocco Date: Sat, 13 Dec 2014 01:06:05 +0100 Subject: [PATCH 4/4] Fix whitespace --- Alea/Diceware.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Alea/Diceware.hs b/Alea/Diceware.hs index 0311cac..1f3fa7e 100644 --- a/Alea/Diceware.hs +++ b/Alea/Diceware.hs @@ -13,9 +13,9 @@ parseDiceware x = map (last . split ' ') $ lines x -- Lookup word with dice index readDiceware :: Diceware -> Int -> String readDiceware d n = show n ++ " -> " ++ - case (undice n) of - Just x -> d !! x - Nothing -> "Does not exist" + case (undice n) of + Just x -> d !! x + Nothing -> "Does not exist" -- Lookup word with linear index readDiceware' :: Diceware -> Int -> String @@ -25,4 +25,4 @@ readDiceware' d n = d !! n -- Ex. undice 11121 == Just 6 undice :: Int -> Maybe Int undice n = elemIndex n . filter - (null . (intersect "0789") . show) $ [11111..66666] + (null . (intersect "0789") . show) $ [11111..66666]