-
I have a situation where I want to match on a sum type when I already know the variant so that I can extract the inner value of the variant. The issue is that to satisfy the type system I have to handle the case where the value does not match the variant. I would like something like a panic or a type that unifies with every other type, but causes undefined behavior when constructed. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There's currently nothing like that in the language and I'm trying to be careful with it, as this is a specification language and it should incentivize people to define what happens in every single scenario. However, I know that some scenarios are just obviously impossible and it's annoying to have to handle them. Therefore, I plan to really soon add Since I haven't implemented that yet, I'll give you a version I'm using in the meantime that works but is quite hacky. Please use it with discretion 😬 pure def unwrap(value: Option[a]): a = {
match value {
| None => Map().get(value)
| Some(x) => x
}
} PS: You should be able to make your thing return an option type and then use this. You could also have a similar definition for your sum type, but that I think is less advisable. |
Beta Was this translation helpful? Give feedback.
There's currently nothing like that in the language and I'm trying to be careful with it, as this is a specification language and it should incentivize people to define what happens in every single scenario. However, I know that some scenarios are just obviously impossible and it's annoying to have to handle them. Therefore, I plan to really soon add
unwrap()
to the language (which takes an option type and causes undefined behavior/error when called onNone
).Since I haven't implemented that yet, I'll give you a version I'm using in the meantime that works but is quite hacky. Please use it with discretion 😬