Mad Libs: Difference between revisions
→{{header|Haskell}}: Fixed wiki formatting glitch (adjusting some names) + hlint, hindent, specified imports
(Added code and example input/output initially omitted) |
(→{{header|Haskell}}: Fixed wiki formatting glitch (adjusting some names) + hlint, hindent, specified imports) |
||
Line 1,219:
=={{header|Haskell}}==
This will read a template story via stdin with no arguments, or read from a file if given as an argument.
<lang Haskell>import System.IO (stdout, hFlush)
import
import qualified Data.Map as M (Map, lookup, insert, empty)
getLines :: IO [String]
getLines =
prompt :: String -> IO String
Line 1,236 ⟶ 1,238:
getKeyword :: String -> Maybe String
getKeyword ('<':xs) =
getKeyword _
parseText :: String -> M.Map String String -> IO String
parseText []
parseText line@(l:lx) keywords =
case getKeyword line of
Nothing -> (l :)
Just keyword -> do
let rest = drop (length keyword) line
case M.lookup keyword keywords of
Nothing
Just knownword -> do
main :: IO ()
main = do
args
nlines
case args of
[] -> unlines
arg:_ -> readFile arg
putStrLn ""
putStrLn
=={{header|J}}==
|