{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE TypeFamilies #-}
module Data.Tree.BST.Intern.Constructors
( BST (EmptyBST, ForkBST),
)
where
import Data.Kind (Type)
import Data.Tree.BST.Invariants (GtN, LtN)
import Data.Tree.ITree (Tree (EmptyTree, ForkTree))
import Data.Tree.Node (Node)
import Prelude
( Bool (True),
Show (show),
String,
(++),
)
data BST :: Tree -> Type where
EmptyBST :: BST 'EmptyTree
ForkBST ::
(Show a, LtN l n ~ 'True, GtN r n ~ 'True) =>
BST l ->
Node n a ->
BST r ->
BST ('ForkTree l (Node n a) r)
instance Show (BST t) where
show :: BST t -> String
show BST t
EmptyBST = String
"E"
show (ForkBST BST l
l Node n a
n BST r
r) = String
"F " String -> ShowS
forall a. [a] -> [a] -> [a]
++ BST l -> String
forall (t :: Tree). BST t -> String
go BST l
l String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Node n a -> String
forall a. Show a => a -> String
show Node n a
n String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ BST r -> String
forall (t :: Tree). BST t -> String
go BST r
r
where
go :: BST t' -> String
go :: forall (t :: Tree). BST t -> String
go BST t'
EmptyBST = String
"E"
go (ForkBST BST l
l' Node n a
n' BST r
r') = String
"(F " String -> ShowS
forall a. [a] -> [a] -> [a]
++ BST l -> String
forall (t :: Tree). BST t -> String
go BST l
l' String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Node n a -> String
forall a. Show a => a -> String
show Node n a
n' String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ BST r -> String
forall (t :: Tree). BST t -> String
go BST r
r' String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
")"