Cleanup
This commit is contained in:
@@ -72,13 +72,13 @@ composeTreeRand :: RandomGen g => Tree (a -> Maybe a, Tree a) -> State g (Tree a
|
||||
composeTreeRand (Node (_,t) ts) = attachListR t ts
|
||||
|
||||
attachListR :: RandomGen g => Tree a -> [Tree (a -> Maybe a, Tree a)] -> State g (Tree a)
|
||||
attachListR t xs = fmap shiftChildren $ foldrM newfRand (fmap ([],) t) xs
|
||||
attachListR t xs = shiftChildren <$> foldrM newfRand (fmap ([],) t) xs
|
||||
|
||||
newfRand :: RandomGen g => Tree (a -> Maybe a,Tree a) -> Tree ([Tree a],a)
|
||||
-> State g (Tree ([Tree a],a))
|
||||
newfRand t = updateRandNode (isJust . upf . snd) ( (root . _2 %~ g) . (root . _1 .:~ composeTree t ) )
|
||||
where
|
||||
upf = (t ^?! root . _1)
|
||||
upf = t ^?! root . _1
|
||||
g x = fromMaybe x (upf x)
|
||||
|
||||
composeTree :: Tree (a -> Maybe a, Tree a) -> Tree a
|
||||
@@ -90,7 +90,7 @@ attachList t xs = shiftChildren $ foldr newf (fmap ([],) t) xs
|
||||
newf :: Tree (a -> Maybe a,Tree a) -> Tree ([Tree a],a) -> Tree ([Tree a],a)
|
||||
newf t = safeUpdateSingleNode (isJust . upf . snd) ( (root . _2 %~ g) . (root . _1 .:~ composeTree t ) )
|
||||
where
|
||||
upf = (t ^?! root . _1)
|
||||
upf = t ^?! root . _1
|
||||
g x = fromMaybe x (upf x)
|
||||
|
||||
shiftChildren :: Tree ([Tree a],a) -> Tree a
|
||||
|
||||
@@ -5,11 +5,10 @@ A /trunk/ refers to the successive first nodes in lists of children.
|
||||
-}
|
||||
module Dodge.Tree.GenerateStructure
|
||||
where
|
||||
import Dodge.RandomHelp
|
||||
import RandomHelp
|
||||
|
||||
import Data.Tree
|
||||
import Control.Monad.State
|
||||
import System.Random
|
||||
{- Single branched tree (a trunk). -}
|
||||
treePath :: Int -> Tree ()
|
||||
treePath 0 = Node () []
|
||||
|
||||
Reference in New Issue
Block a user