Work from the rules of production,
S -> ab | aSb
we could write
s = ["ab"] ++ [ "a" ++ x ++ "b" | x <- s ]
so that
~> take 5 s ["ab","aabb","aaabbb","aaaabbbb","aaaaabbbbb"] it :: [[Char]]
Your attempt may work with a little change,
[ x ++ y | x <- ["a","aa",..] | y <- ["b","bb",..]]
to use the parallel list extension ( :set -XParallelListComp in GHCi), except for enumerations. But itβs easy to fix,
[ x ++ y | x <- [replicate n 'a' | n <- [1..]] | y <- [replicate n 'b' | n <- [1..]]]
source share