Skip to content

Commit

Permalink
Correctly apply the import rename to ADTs
Browse files Browse the repository at this point in the history
  • Loading branch information
developedby committed Oct 6, 2024
1 parent 71e2600 commit 7b518b7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/fun/transform/encode_adts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn encode_ctr_num_scott<'a>(ctr_args: impl DoubleEndedIterator<Item = &'a Name>
Term::rfold_lams(term, ctr_args.cloned().map(Some))
}

fn encode_num_scott_tag(tag : u32, ctr_name: &Name, source: Source) -> Definition {
fn encode_num_scott_tag(tag: u32, ctr_name: &Name, source: Source) -> Definition {
let tag_nam = Name::new(format!("{ctr_name}/tag"));
let rules = vec![Rule { pats: vec![], body: Term::Num { val: Num::U24(tag) } }];
Definition::new_gen(tag_nam.clone(), rules, source, true)
Expand Down
1 change: 1 addition & 0 deletions src/imports/book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ impl ParseBook {
name = Name::new(format!("__{}", name));
}

adt.name = name.clone();
adts_map.push((old_name, name.clone()));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/golden_tests/import_system/import_type.bend
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from lib/MyOption import (MyOption, MyOption/bind, MyOption/wrap)

def main():
def main() -> MyOption((u24, u24)):
with MyOption:
a <- MyOption/Some(1)
b <- MyOption/Some(2)
Expand Down
8 changes: 5 additions & 3 deletions tests/golden_tests/import_system/lib/MyOption.bend
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
type MyOption = (Some val) | (None)
type MyOption(A):
Some { val: A }
None

def MyOption/bind(val, nxt):
def MyOption/bind(val: MyOption(A), nxt: (Id -> Id) -> A -> MyOption(B)) -> MyOption(B):
match val:
case MyOption/Some:
nxt = undefer(nxt)
return nxt(val.val)
case MyOption/None:
return MyOption/None

def MyOption/wrap(val):
def MyOption/wrap(val: A) -> MyOption(A):
return MyOption/Some(val)

0 comments on commit 7b518b7

Please sign in to comment.