-
-
Notifications
You must be signed in to change notification settings - Fork 132
Closed
Description
What is your idea? Provide a use case.
We need union types like Haskell provides. For example, I want to extract output values from a list. It can be List<Input> or List<Output>. If I write a unified function like this:
fn extract_utxos(items: List<a>) -> a {
let utxos =
when list.head(items) is {
Some(Input { .. }) -> todo @"extract outputs"
Some(Output { .. }) -> todo @"use as is"
}
todo @"rest"
}So, I can't determine which type I use. It would be a good idea to check a if it is Input or Output, but Aiken doesn't allow it.
Why is it a good idea?
If we had the ability to do something like:
fn extract_utxos(items: List<Input|Output>) -> ait would be amazing. It would open up more possibilities to write cleaner, more abstract, and more readable code.
What is the current alternative and why is it not good enough?
The current alternative is defining a custom type, such as:
type InOut {
In(List<Input>)
Out(List<Output>)
}And then match it with your value, but that's not the goal we want to achieve by refactoring and extracting functions. There should be less code and fewer entities, not more. So, it is not good enough.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
🚀 Released
