<commit_before>module DataShow where
import Data
import Data.List (intercalate)

showSubst f s = "[" ++ intercalate ", " (map (\(i,t) -> f i ++ " -> " ++ show t) s) ++  "]"

instance Show State where
  show (State subst state index vars) = "St " ++ showSubst (\i -> "x." ++ show i) subst ++
--                                        "\n" ++ showSubst id (map (\x -> (x, state x)) vars) ++
                                        " " ++ show index

instance Show Term where
  show (Var v) = v
  show (Free i) = "x." ++ show i
  show (Ctor ctor ts) =
    case ctor of
      "Nil" -> "[]"
      "Cons" -> let [h,t] = ts
                in  show h ++ ":" ++ show t
      _ | null ts -> ctor
      _ ->  ctor ++ showList ts ""

instance Show Goal where
  show t =
    show' t []
    where
      show' (Fresh v g) fresh = show' g (v:fresh)
      show' g fresh =
        (if null fresh then "" else "Fresh " ++ unwords fresh ++ " ") ++
        case g of
          Unify l r -> show l ++ " === " ++ show r
          Conj  l r -> "(" ++ show l ++ ") &&& (" ++ show r ++ ")"
          Disj  l r -> "(" ++ show l ++ ") ||| (" ++ show r ++ ")"
          Invoke n args -> "Invoke " ++ n ++ " with " ++ show args
          Zzz g -> "Zzz " ++ show g

instance Show a => Show (Stream a) where
  show Empty = "[]"
  show (Mature a s) = show a ++ " :\n" ++ show s
  show (Immature s) = "Immature " ++ show s

instance Show Tree where
  show t =
    show' t 0
    where
      nSpaces n = replicate n ' '
      show' t n =
        case t of
          Fail                        -> nSpaces n ++ "F"
          Success st                  -> nSpaces n ++ "S " ++ show st
          Renaming i st g             -> nSpaces n ++ "R " ++ show i ++ " " ++ show st ++ " (" ++ show g ++ ")"
          Step     i st g fv ch       -> nSpaces n ++ "T " ++ show fv ++ " " ++ show i ++ " " ++ show st ++ " (" ++ show g ++ ")" ++ "\n" ++ show' ch (n+1)
          Or       i st g ch          -> nSpaces n ++ "O " ++ show i ++ " " ++ show st ++ " (" ++ show g ++ ")" ++ "\n" ++ intercalate "\n" (map (\x -> show' x (n+1)) ch)
          Split    i st g1 g2 ch1 ch2 -> nSpaces n ++ "G " ++ show i ++ " " ++ show st ++ " (" ++ show g1 ++ ")" ++ " (" ++ show g2 ++ ")" ++ "\n" ++ show' ch1 (n+1) ++ "\n" ++ show' ch2 (n+1)
          Gen      i st subst g ch    -> nSpaces n ++ "A " ++ show i ++ " " ++ show st ++ " <" ++ show subst ++ "> "  ++ " (" ++ show g ++ ")" ++ "\n" ++ show' ch (n+1)

instance Show Def where
  show x = "let " ++ name x ++ " " ++ unwords (args x) ++ " = " ++ show (body x)<commit_msg>Prettier goal printing<commit_after>module DataShow where
import Data
import Data.List (intercalate)

showSubst f s = "[" ++ intercalate ", " (map (\(i,t) -> f i ++ " -> " ++ show t) s) ++  "]"

instance Show State where
  show (State subst state index vars) = "St " ++ showSubst (\i -> "x." ++ show i) subst ++
--                                        "\n" ++ showSubst id (map (\x -> (x, state x)) vars) ++
                                        " " ++ show index

instance Show Term where
  show (Var v) = v
  show (Free i) = "x." ++ show i
  show (Ctor ctor ts) =
    case ctor of
      "Nil" -> "[]"
      "Cons" -> let [h,t] = ts
                in  "(" ++ show h ++ ":" ++ show t ++ ")"
      _ | null ts -> ctor
      _ ->  ctor ++ showList ts ""

instance Show Goal where
  show t =
    show' t []
    where
      show' (Fresh v g) fresh = show' g (v:fresh)
      show' g fresh =
        (if null fresh then "" else "Fresh " ++ unwords (reverse fresh) ++ " ") ++
        case g of
          Unify l r -> show l ++ " === " ++ show r
          Conj  l r -> "(" ++ show l ++ ") &&& (" ++ show r ++ ")"
          Disj  l r -> "(" ++ show l ++ ") ||| (" ++ show r ++ ")"
          Invoke n args -> n ++ " " ++ unwords (map show args)
          Zzz g -> "Zzz " ++ show g

instance Show a => Show (Stream a) where
  show Empty = "[]"
  show (Mature a s) = show a ++ " :\n" ++ show s
  show (Immature s) = "Immature " ++ show s

instance Show Tree where
  show t =
    show' t 0
    where
      nSpaces n = replicate n ' '
      show' t n =
        case t of
          Fail                        -> nSpaces n ++ "F"
          Success  st                 -> nSpaces n ++ "S " ++ show st
          Renaming i st g             -> nSpaces n ++ "R " ++ show i ++ " " ++ show st ++ " (" ++ show g ++ ")"
          Step     i st g fv ch       -> nSpaces n ++ "T " ++ show fv ++ " " ++ show i ++ " " ++ show st ++ " (" ++ show g ++ ")" ++ "\n" ++ show' ch (n+1)
          Or       i st g ch          -> nSpaces n ++ "O " ++ show i ++ " " ++ show st ++ " (" ++ show g ++ ")" ++ "\n" ++ intercalate "\n" (map (\x -> show' x (n+1)) ch)
          Split    i st g1 g2 ch1 ch2 -> nSpaces n ++ "G " ++ show i ++ " " ++ show st ++ " (" ++ show g1 ++ ")" ++ " (" ++ show g2 ++ ")" ++ "\n" ++ show' ch1 (n+1) ++ "\n" ++ show' ch2 (n+1)
          Gen      i st subst g ch    -> nSpaces n ++ "A " ++ show i ++ " " ++ show st ++ " <" ++ show subst ++ "> "  ++ " (" ++ show g ++ ")" ++ "\n" ++ show' ch (n+1)

instance Show Def where
  show x = "let " ++ name x ++ " " ++ unwords (args x) ++ " = " ++ show (body x)
{'fraction_non_alphanumeric': 0.20491962037575054, 'fraction_numerical': 0.005423203563819485, 'mean_word_length': 1.5488647581441264, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1017108', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1747, 'n_words': 648}