Hello all,<br><br>I have a very interesting alternative solution of the problem. First I generate a tree with all the permutations:<br><br>eg if I want to find al permutations of ao, I get the following tree<br><br> [a @]<br>
| |<br> [o 0] [o 0]<br><br>Then I walk trough the tree so I can print it. There is only one ugly thing. Showtree' returns a string (in our example aoa0@o@0). To make it a list i put a \n between a left and right node and then use lines to make it a list of strings. Can someone point me in the right direction how to beautify it a bit?<br>
<br>I also have an annoying problem with gmail and firefox. It seems it doesn add my posts to the current thread, but starts a new one. Oh well think I switch to evolution. I will review all yours solutions tomorrow. I saw some very beautifull things. <br>
<br>With kind regards,<br><br>Edgar Klerks<br><br>module Main where<br>import Data.Char<br><br>data WordTree = Chain (Char,WordTree)<br> | Choice (Char, WordTree) (Char, WordTree)<br> | Stop<br><br>instance Show WordTree where<br>
show = unlines.showTree<br><br>type Rule = (Char, Char)<br>type Rules = [Rule]<br><br>infixl 4 ==><br><br>a ==> b = (a,b)<br><br>rules :: Rules<br>rules = [ 'a' ==> '@', 'l' ==> '|']<br>
<br><br>buildTree :: String -> Rules -> WordTree<br>buildTree [] r = Stop<br>buildTree (c:cs) r = case lookup c r of<br> Just a -> Choice (a, buildTree cs r) (c, buildTree cs r)<br> Nothing -> Chain (c, buildTree cs r)<br>
<br><br>showTree a = lines $ showTree' a []<br><br>showTree' (Chain (a,b)) p = a : showTree' b p<br>showTree' (Choice (a,b) (c,d)) p = c : showTree' d p ++ "\n" ++ (a : showTree' b p) <br>
showTree' (Stop) p = p<br><br>