Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Haskell Tree example
--ghc 7.10 main = putStr$show$maketree [1,2,5,7,4,5,3,2,8,6] -- Tree data Tree a = Empty | Node { v::a, l::Tree a, r::Tree a } -- maketree insert x Empty = Node x Empty Empty insert x t@(Node v l r) = case compare x v of GT -> Node v l (insert x r) LT -> Node v (insert x l) r EQ -> t maketree = foldr insert Empty -- show Tree instance (Show a) => Show (Tree a) where show t = foldr (++) "" [showline n t | n <- [1..depth t]] tmux Empty z _ = z tmux _ _ v = v depth t = tmux t 0 $ 1 + max (depth$l t) (depth$r t) sep t = tmux t "" " " space s = replicate (length s) ' ' under s = replicate (length s) '_' showt _ _ _ _ Empty = "" showt sl sv sr 1 t = (sl$l t) ++ (sv$v t) ++ (sr$r t) showt sl sv sr n t = (st$l t) ++ (sep$l t) ++ (space$show$v t) ++ (sep$r t) ++ (st$r t) where st = showt sl sv sr (n-1) showvals n = showt (space.divl) show (space.divr) n showdivs n = showt divl (space.show) divr n divl t = tmux t "" $ (space ((divl$l t) ++ (show$v t))) ++ (under$divr$r t) ++ "/" divr t = tmux t "" $ "\\" ++ (under$divl$l t) ++ (space ((show$v t) ++ (divr$r t))) showline n t = (showvals n t) ++ "\n" ++ (showdivs n t) ++ "\n"
run
|
edit
|
history
|
help
0
haskell_exam
Token
Semilattice
Lambda Parser with long ids
mapper
prettier Tasty
boolean functions of zero arguments in haskell
Perfect numbers
appending and prepending list
Cubed