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

Provide a mechanism for non-terminating cast from Data #889

Closed
KtorZ opened this issue Mar 20, 2024 · 0 comments · Fixed by #959
Closed

Provide a mechanism for non-terminating cast from Data #889

KtorZ opened this issue Mar 20, 2024 · 0 comments · Fixed by #959
Assignees
Labels
code gen Untyped Plutus Core code generation parsing Parser work typechecking Types and inference

Comments

@KtorZ
Copy link
Member

KtorZ commented Mar 20, 2024

What is your idea? Provide a use case.

We want to provide ways to safely cast between types similar to expect, but without crashing the entire program on failure.

This could be introduced via a new syntax, to not overload expect from its current semantic. Something along the lines of:

if unknown is Foo {
  ... 
} else if unknown is Bar {
  ...
} else {
  ...
}

where Foo and Bar are type annotations. Within each branch, the type of unknown would be respectively Foo, Bar and Data.

Why is it a good idea?

This is particularly useful for casting from an unknown type (i.e. Data) from within an iterator (e.g. foldr).

What is the current alternative and why is it not good enough?

Alternative right now requires a lot of boilerplate and the explicit use of builtin functions such as choose_data.

@KtorZ KtorZ added parsing Parser work typechecking Types and inference code gen Untyped Plutus Core code generation labels Mar 20, 2024
@KtorZ KtorZ added this to the 1.0.26-alpha milestone Mar 20, 2024
@KtorZ KtorZ changed the title Provide a mechanism for non-terminating expect Provide a mechanism for non-terminating cast from Data Mar 20, 2024
@KtorZ KtorZ removed this from the 1.0.27-alpha milestone Apr 4, 2024
@rvcas rvcas self-assigned this Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code gen Untyped Plutus Core code generation parsing Parser work typechecking Types and inference
Projects
Status: ✅ In Next Release
Development

Successfully merging a pull request may close this issue.

3 participants