This is my first program on my second try to learn haskell :)import Data.Maybe (mapMaybe)import Control.Exception (try, IOException)import System.Environment (getArgs)type Rule = (Char, String)type Axiom = Stringtype LSystem = (Axiom, [Rule])getRule :: Char -> [Rule] -> StringgetRule ch [] = [ch]getRule ch ((rulekey, rulevalue):rest)        | ch == rulekey = rulevalue        | otherwise = getRule ch restlSystemIterate :: Int -> LSystem -> StringlSystemIterate 0 (axiom, _) = axiomlSystemIterate n (axiom, rules) =        lSystemIterate (n-1)        (concatMap (\ch -> getRule ch rules) axiom, rules)splitRule :: String -> Maybe (Char, String)splitRule (x:' ':rest) = Just (x,rest)splitRule _ = NothingreadLSystem :: String -> IO (Maybe LSystem)readLSystem filename = do        strorexc <- try $ readFile filename :: IO (Either IOException String)        case strorexc of                Left _ -> return Nothing                Right [] -> return Nothing                Right str -> return (Just (ax, mapMaybe splitRule rules))                             where (ax:rules) = lines striterateIOMaybe :: Int -> IO (Maybe LSystem) -> IO (Maybe String)iterateIOMaybe n = fmap $ fmap (lSystemIterate n)main = do        args <- getArgs        case args of                (n:filename:[]) -> do                        maybelsystem <- readLSystem filename                        case maybelsystem of                                Just lsystem -> putStrLn $ lSystemIterate (read n) lsystem                                Nothing -> putStrLn File doesn't exist, or it is empty                _ -> putStrLn Usage: progname iterations filenameProgram invocation is something like this: runhaskell lsystem.hs 3 dragon.ls assuming that it is saved as lsystem.hs.It takes two arguments, first argument is number of iterations, second argument is a filename to read L-System from.File structure is simple, first line is axiom, each line of the form 'x ys' treated as transformation rule. So, something like this:FXX X+YF+Y -FX-YAs output, program should return something like;FX+YF++-FX-YF++-FX+YF+--FX-YF+So, how does it look?
L system equations
haskell;functional programming