mirror of
https://github.com/anoma/juvix.git
synced 2024-12-11 08:25:46 +03:00
Fix de Brujin indexing of lambda arguments (#1727)
A lambda: ``` \ { v0 := b0 ; v1 := b1 ; ... ; vn := bn } ``` should be translated to: ``` λ? (λ? ... (λ? (match ?$0, ?$1, ... , ?$n with ...))) ``` i.e the de Brujin index of the values in the match always start from 0. Fixes: https://github.com/anoma/juvix/issues/1695
This commit is contained in:
parent
d5bd3d4fa1
commit
0ac9eb1ab4
@ -298,19 +298,13 @@ goLambda l = do
|
||||
local
|
||||
(over indexTableVarsNum (+ nPatterns))
|
||||
(mapM goLambdaClause (l ^. Internal.lambdaClauses))
|
||||
values' <- values
|
||||
let match = mkMatch' (fromList values') (toList ms)
|
||||
return $ foldr (\_ n -> mkLambda' n) match values'
|
||||
let values = take nPatterns (mkVar' <$> [0 ..])
|
||||
match = mkMatch' (fromList values) (toList ms)
|
||||
return $ foldr (\_ n -> mkLambda' n) match values
|
||||
where
|
||||
nPatterns :: Int
|
||||
nPatterns = length (l ^. Internal.lambdaClauses . _head1 . Internal.lambdaPatterns)
|
||||
|
||||
values :: Sem r [Node]
|
||||
values = do
|
||||
varsNum <- asks (^. indexTableVarsNum)
|
||||
let vs = take nPatterns [varsNum ..]
|
||||
return (mkVar' <$> vs)
|
||||
|
||||
goAxiomInductive ::
|
||||
forall r.
|
||||
Members '[InfoTableBuilder, Reader InternalTyped.TypesTable, Reader Internal.InfoTable] r =>
|
||||
|
@ -163,5 +163,10 @@ tests =
|
||||
"Builtin Inductive type"
|
||||
$(mkRelDir ".")
|
||||
$(mkRelFile "BuiltinInductive.juvix")
|
||||
$(mkRelFile "out/BuiltinInductive.out")
|
||||
$(mkRelFile "out/BuiltinInductive.out"),
|
||||
PosTest
|
||||
"Higher Order Lambda"
|
||||
$(mkRelDir ".")
|
||||
$(mkRelFile "HigherOrderLambda.juvix")
|
||||
$(mkRelFile "out/HigherOrderLambda.out")
|
||||
]
|
||||
|
14
tests/Internal/positive/HigherOrderLambda.juvix
Normal file
14
tests/Internal/positive/HigherOrderLambda.juvix
Normal file
@ -0,0 +1,14 @@
|
||||
module HigherOrderLambda;
|
||||
|
||||
open import Stdlib.Prelude;
|
||||
|
||||
map' : {A : Type} → {B : Type} → (A → B) → List A → List B;
|
||||
map' f := \{ nil := nil; (h :: t) := f h :: map' f t};
|
||||
|
||||
lst : List Nat;
|
||||
lst := zero :: one :: nil;
|
||||
|
||||
main : IO;
|
||||
main := printNatLn (foldr (+) zero (map' ((+) one) lst));
|
||||
|
||||
end;
|
1
tests/Internal/positive/out/HigherOrderLambda.out
Normal file
1
tests/Internal/positive/out/HigherOrderLambda.out
Normal file
@ -0,0 +1 @@
|
||||
suc (suc (suc zero))
|
Loading…
Reference in New Issue
Block a user