Feedback requested: A sample implementation of L-systems in Haskell

A while back I published a draft of an article I wrote to explore L-systems, specifically D0L systems, and would very much enjoy any feedback (positive or negative) of what I have written.

A sample implementation of L-systems in Haskell

Primarily, the content which gives me pause is the mathematics revolving morphic words as I have yet to fully grok them in any greater sense than the one that I have used in my implementation.

Please, critique my work and point out any errors.

Kind regards,
Filip Allberg

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.


Monad was Used to Sequence Operations on the Internet

Yeah, nice. But I don't like your last monadic description of L-system. You completely abstracted even over the theory of L-systems to arrive at a solution which doesn't say much more than that a monad can be applied n times. Wrong abstraction. Not my thing.

Dude. Hammer, Nail.

Says it more clearly.

data D0L a = D0L { axiom :: [a]
                   , rules :: a -> [a]

eval :: D0L a -> D0L a
eval (D0L axiom rules) = D0L (concatMap rules axiom) rules

algae :: D0L Char
algae = D0L "A" rules
  where rules 'A' = "AB"
        rules 'B' = "A"

pythagoras :: D0L Char
pythagoras = D0L "0" rules
  where rules '0' = "1[0]0" 
        rules '1' = "11"
        rules '[' = "["
        rules ']' = "]"

main :: IO ()
main = do
  putStrLn "6 generations of algae"
  mapM_ (putStrLn . axiom) . take 6 $ iterate eval algae

  putStrLn ""

  putStrLn "4 generations of Pythagoras tree"
  mapM_ (putStrLn . axiom) . take 4 $ iterate eval pythagoras

The above code works equally well. Still, wouldn't be what I would like, but gets rid of an abstraction you simply don't need.

For reference, what would

For reference, what would you prefer?

Initially, we identify an

Initially, we identify an approach to represent a particular L-system, and apply the same line of reasoning to represent other such systems.

Thereafter we will abstract away representing a specific L-system to afford ourselves a framework for representing any valid L-system.

Perhaps the framework is a little too big and general? What rules out a definition such as the following:

algae :: D0L Char
algae = D0L "A" rules
where rules 'A' = "AC"
rules 'B' = "A"