Skip to content

Instantly share code, notes, and snippets.

@freddi301
Created July 24, 2024 15:03
Show Gist options
  • Save freddi301/0e66c1bd868f58d501d7ae0f6955cc7a to your computer and use it in GitHub Desktop.
Save freddi301/0e66c1bd868f58d501d7ae0f6955cc7a to your computer and use it in GitHub Desktop.
Heap allocated object in Idris2
data Heap : Nat -> (Nat -> Type) -> Type where
Lin : Heap Z a
(:<) : Heap l a -> a l -> Heap (S l) a
data Tree : Nat -> Type where
Leaf : String -> Tree n
Branch : Fin n -> Fin n -> Tree n
u1 : Heap 4 Tree
u1 = [<
Leaf "a",
Leaf "b",
Branch 0 1,
Branch 2 2
]
data FVTree : {v : Type} -> (a : v -> Type) -> v -> Type where
FVLeaf :
{v : Type} -> {a : v -> Type} -> {vi : v} ->
String -> FVTree a vi
FVBranch :
{v : Type} -> {a : v -> Type} -> {vi : v} ->
a vi -> a vi -> FVTree a vi
u2 : Heap 4 (FVTree Fin)
u2 = [<
FVLeaf "a",
FVLeaf "b",
FVBranch 0 1,
FVBranch 2 2
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment