Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utility functions #11

Open
8 tasks
steinerkelvin opened this issue Jun 15, 2024 · 0 comments
Open
8 tasks

Utility functions #11

steinerkelvin opened this issue Jun 15, 2024 · 0 comments

Comments

@steinerkelvin
Copy link
Member

We should be able to provide functions like benda.util.to_tree(xs: Iterable[T]) -> Tree[T] native-optimized, though I'm not sure on the interface format.

We should also be able to iterate over Tree and List easily and
native-optimizedly with functions like benda.util.from_tree(tree: Tree[T]) -> Iterator[T]:

tree = book.adts.Tree.Node(…, …, …)
for x in benda.util.iter_tree(tree):
   print(x)

I'm inclined to think we should not provide this __iter__ behavior directly on
the types of Tree.Node etc because this behavior is not that obvious and is
implemented as separate functions on Bend's side.


  • benda.util.to_nat(int) -> Nat throws ValueError("Negative integer")
  • benda.util.from_nat(Nat) -> int
  • benda.util.to_string(str) -> String
  • benda.util.from_string(String) -> str
  • benda.util.to_list(Iterable[T]) -> List[T]
  • benda.util.from_list(List[T]) -> list[T]
  • benda.util.iter_list(List[T]) -> Iterator[T]
  • benda.util.iter_tree(Tree[T]) -> Iterator[T]

Note: str conversion from and to String should probably also automatic, but we can't
do that for intNat because they don't map directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant