[sc-441] Fix encoding of string patterns

This commit is contained in:
Nicolas Abril 2024-02-28 13:09:00 +01:00
parent 7b859fc41e
commit fb8f3fefc7
4 changed files with 17 additions and 3 deletions

View File

@ -104,11 +104,11 @@ impl Pattern {
}
fn encode_str(str: &str) -> Pattern {
let lnil = Pattern::Ctr(Name::from(LNIL), vec![]);
let lnil = Pattern::Ctr(Name::from(SNIL), vec![]);
str.chars().rfold(lnil, |tail, head| {
let head = Pattern::Num(NumCtr::Num(head as u64));
Pattern::Ctr(Name::from(LCONS), vec![head, tail])
Pattern::Ctr(Name::from(SCONS), vec![head, tail])
})
}
}

View File

@ -0,0 +1,9 @@
(is_as "As") = 2
(is_as "as") = 2
(is_as "") = 1
(is_as *) = 0
map f (List.cons x xs) = (List.cons (f x) (map f xs))
map f [] = []
main = (map is_as ["As" "as" "" "Asd" "qwerty" "AAs"])

View File

@ -0,0 +1,5 @@
---
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/match_str.hvm
---
[2, 2, 1, 0, 0, 0]

View File

@ -2,6 +2,6 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/simplify_matches/match_str.hvm
---
(is_as) = λa match a { (List.cons b c): (match b { 65: λd (match d { (List.cons f g): λh (match f { 115: λ* λj (match j { (List.cons * *): λ* 0; (List.nil): λ* 2 } *); *: λ* λ* 0 } h g); (List.nil): λ* 0 } *); 97: λhb (match hb { (List.cons jb kb): λlb (match jb { 115: λ* λnb (match nb { (List.cons * *): λ* 0; (List.nil): λ* 2 } *); *: λ* λ* 0 } lb kb); (List.nil): λ* 0 } *); *: λ* 0 } c); (List.nil): 1 }
(is_as) = λa match a { (String.cons b c): (match b { 65: λd (match d { (String.cons f g): λh (match f { 115: λ* λj (match j { (String.cons * *): λ* 0; (String.nil): λ* 2 } *); *: λ* λ* 0 } h g); (String.nil): λ* 0 } *); 97: λhb (match hb { (String.cons jb kb): λlb (match jb { 115: λ* λnb (match nb { (String.cons * *): λ* 0; (String.nil): λ* 2 } *); *: λ* λ* 0 } lb kb); (String.nil): λ* 0 } *); *: λ* 0 } c); (String.nil): 1 }
(main) = *