<commit_before>{-# LANGUAGE UnicodeSyntax #-}

------------------------------------------------------------------------------
-- Using mutual data types
data Tree a   = Tree a (Forest a)
data Forest a = Fnil | Fcons (Tree a) (Forest a)

mapForest ∷ (Tree a → Tree b) → Forest a → Forest b
mapForest _ Fnil         = Fnil
mapForest f (Fcons t ts) = Fcons (f t) (mapForest f ts)

reverseForest ∷ Forest a → Forest a
reverseForest ts = revForest ts Fnil
  where
  revForest ∷ Forest a → Forest a → Forest a
  revForest Fnil         ys = ys
  revForest (Fcons x xs) ys = revForest xs (Fcons x ys)

mirrorTree ∷ Tree a → Tree a
mirrorTree (Tree t ts) = Tree t (reverseForest (mapForest mirrorTree ts))

-- Using a single data type
data RoseTree a = RoseTree a [RoseTree a]

mirrorRoseTree ∷ RoseTree a → RoseTree a
mirrorRoseTree (RoseTree a ts) = RoseTree a (reverse (map mirrorRoseTree ts))<commit_msg>[ doc ] s/mutual data types/mutually recursive data types.<commit_after>{-# LANGUAGE UnicodeSyntax #-}

------------------------------------------------------------------------------
-- Using mutually recursive data types
data Tree a   = Tree a (Forest a)
data Forest a = Fnil | Fcons (Tree a) (Forest a)

mapForest ∷ (Tree a → Tree b) → Forest a → Forest b
mapForest _ Fnil         = Fnil
mapForest f (Fcons t ts) = Fcons (f t) (mapForest f ts)

reverseForest ∷ Forest a → Forest a
reverseForest ts = revForest ts Fnil
  where
  revForest ∷ Forest a → Forest a → Forest a
  revForest Fnil         ys = ys
  revForest (Fcons x xs) ys = revForest xs (Fcons x ys)

mirrorTree ∷ Tree a → Tree a
mirrorTree (Tree t ts) = Tree t (reverseForest (mapForest mirrorTree ts))

-- Using a single data type
data RoseTree a = RoseTree a [RoseTree a]

mirrorRoseTree ∷ RoseTree a → RoseTree a
mirrorRoseTree (RoseTree a ts) = RoseTree a (reverse (map mirrorRoseTree ts))
{'fraction_non_alphanumeric': 0.16118598382749327, 'fraction_numerical': 0.0, 'mean_word_length': 2.430683918669131, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4027863', 'n_tokens_mistral': 641, 'n_tokens_neox': 598, 'n_words': 273}