You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
data LHeap = E | H Int LHeap LHeap
rank :: LHeap -> Int
rank x = case x of
E -> 0
H y z r -> rank r + 1
merge :: LHeap -> LHeap -> LHeap
merge g h =
case g of
E -> h
H a l r -> case h of
E -> g
H b z0 z1 ->
let
s = merge r h
in
if a > b then merge h g
else if rank s > rank l then H a s l
else H a l s
add :: Int -> LHeap -> LHeap
add x h = merge h (H x E E)
pop :: LHeap -> (Int, LHeap)
pop z = case z of
H x l r -> (x, merge l r)
E -> (-1, E)
gibbon_main =
let
_ = printPacked (add 0 E)
in ()
When gibbon is invoked this gives the following error:
cabal v2-exec gibbon -- --packed --no-gc --to-exe ../lheap/lheap.hs
gibbon: Var l_44_118_170_238_248 not found. Checking:
: VarE "l_44_118_170_238_248"
CallStack (from HasCallStack):
error, called at src/Gibbon/L1/Typecheck.hs:746:21 in gibbon-0.2-inplace:Gibbon.L1.Typecheck
To the right of _ = printPacked, replacing (add 0 E) with just E is able to compile and produce the correct representation:
./lheap.exe
(E )'#()
This error was produced in branch issue_191.
The text was updated successfully, but these errors were encountered:
data LHeap = E | H Int LHeap LHeap
rank :: LHeap -> Int
rank x = case x of
E -> 0
H y z r -> rank r + 1
merge :: LHeap -> LHeap -> LHeap
merge g h =
case g of
E -> h
H a l r -> case h of
E -> g
H b z0 z1 ->
let
s = merge r h
in mergeIf a b l s h g
mergeIf :: Int -> Int -> LHeap -> LHeap -> LHeap -> LHeap -> LHeap
mergeIf a b l s h g = if (a > b) then merge h g
else if (rank s > rank l) then mergeIfElse a b s l h g
else H a l s
mergeIfElse :: Int -> Int -> LHeap -> LHeap -> LHeap -> LHeap -> LHeap
mergeIfElse a b s l h g = H a s l
add :: Int -> LHeap -> LHeap
add x h = merge h (H x E E)
pop :: LHeap -> (Int, LHeap)
pop z = case z of
H x l r -> (x, merge l r)
E -> (-1, E)
gibbon_main =
let
_ = printPacked (add 0 E)
in ()
Here's a simpler example that I believe is broken by the same bug.
data I = I Int
data A = A I I
swap :: A -> A
swap x = case x of
A i1 i2 -> A i2 i1
gibbon_main =
let
_ = printPacked (swap (A (I 0) (I 1)))
in ()
gibbon: Var i1_13_57_104_141 not found. Checking:
: VarE "i1_13_57_104_141"
CallStack (from HasCallStack):
error, called at src/Gibbon/L1/Typecheck.hs:746:21 in gibbon-0.2-inplace:Gibbon.L1.Typecheck
Note the following works:
data A = A Int Int
swap :: A -> A
swap x = case x of
A i1 i2 -> A i2 i1
gibbon_main =
let
_ = printPacked (swap (A 0 1))
in ()
Here is a leftist heap implementation in gibbon:
When gibbon is invoked this gives the following error:
To the right of
_ = printPacked
, replacing(add 0 E)
with justE
is able to compile and produce the correct representation:This error was produced in branch
issue_191
.The text was updated successfully, but these errors were encountered: