Skip to content

Instantly share code, notes, and snippets.

@kuribas
Last active September 26, 2020 14:37
Show Gist options
  • Save kuribas/0f7bb1b7059e7af15d735fc7e67798b2 to your computer and use it in GitHub Desktop.
Save kuribas/0f7bb1b7059e7af15d735fc7e67798b2 to your computer and use it in GitHub Desktop.
delta.grin
grinMain = x <- readList 10
x' <- store x
y <- deltaOfDelta x'
y' <- store y
printAll y'
readList n =
b <- _prim_int_gt n 0
if b then
s <- _prim_read_string
i <- _prim_str_int s
m <- _prim_int_sub n 1
x <- readList m
x' <- store x
pure (CCons i x')
else
pure (CNil)
printAll l =
el <- eval l
case el of
(CNil) -> pure (CUnit)
(CCons x y) ->
_prim_int_print x
printAll y
zipWith f l1 l2 =
el1 <- eval l1
el2 <- eval l2
case el1 of
(CNil) -> pure (CNil)
(CCons x xs) ->
case el2 of
(CNil) -> pure (CNil)
(CCons y ys) ->
fx <- apply f x
fxy <- apply fx y
r <- store (FzipWith f xs ys)
pure (CCons fxy r)
delta l =
l2 <- store (CCons 0 l)
sub <- pure (P2sub)
zipWith sub l l2
deltaOfDelta l =
dl <- delta l
dl' <- store dl
delta dl'
apply f x =
case f of
(P2sub) -> pure (P1sub x)
(P1sub x1) -> _prim_int_sub x1 x
eval q =
v <- fetch q
case v of
(CNil) -> pure (CNil)
(CCons y ys) -> pure (CCons y ys)
(FzipWith f l1 l2) -> w <- zipWith f l1 l2
update q w
pure w
(Fdelta l) -> w <- delta l
update q w
pure w
(FdeltaOfDelta l) -> w <- deltaOfDelta l
update q w
pure w
@kuribas
Copy link
Author

kuribas commented Sep 26, 2020

PHASE #2
PipelineStep: T BindNormalisation had effect: None (0.000421 ms)
PipelineStep: T InlineEval
Analysis
PipelineStep: HPT Compile (0.000309 ms)
PipelineStep: HPT RunPure iterations: 6 type-env error: f_8 has illegal type of {P1sub[{T_Int64}]
,P2sub[]
,T_Int64} (1.517150 ms)
Invalidating type environment
had effect: ExpChanged (3.397146 ms)
PipelineStep: SaveGrin (Rel "InlineEval.grin") (0.631404 ms)
PipelineStep: T SparseCaseOptimisation
Analysis
PipelineStep: HPT Compile (0.000336 ms)
PipelineStep: HPT RunPure iterations: 3 (3.030987 ms)
had effect: ExpChanged (4.107001 ms)
PipelineStep: SaveGrin (Rel "SparseCaseOptimisation.grin") (0.301715 ms)
error after SparseCaseOptimisation:
the parameter of fetch is a node type: q.1

illegal code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment