mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-24 03:52:50 -06:00
Expermintation woth a collections framework for transfer.
This commit is contained in:
22
transfer/lib/bintree.tra
Normal file
22
transfer/lib/bintree.tra
Normal file
@@ -0,0 +1,22 @@
|
||||
-- NOTE: this is unfinished and untested
|
||||
|
||||
import prelude
|
||||
|
||||
data BinTree : Type -> Type where
|
||||
Leaf : (A:Type) -> BinTree A
|
||||
Node : (A:Type) -> BinTree A -> A -> BinTree A -> BinTree A
|
||||
|
||||
contains : (A:Type) -> Ord A -> A -> BinTree A -> Bool
|
||||
contains _ _ _ (Leaf _) = False
|
||||
contains A o x (Node _ l y r)
|
||||
| x < y = contains A o x l
|
||||
| x > y = contains A o x r
|
||||
| otherwise = True
|
||||
|
||||
insert : (A:Type) -> Ord A -> A -> BinTree A -> BinTree A
|
||||
insert A o x (Leaf _) = Node A (Leaf A) x (Leaf A)
|
||||
insert A o x (Node _ l y r)
|
||||
| x < y = Node A (insert A o x l) y r
|
||||
| x > y = Node A l y (insert A o x r)
|
||||
| otherwise = Node A l x r
|
||||
|
||||
Reference in New Issue
Block a user