-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
When creating a Result via err(x), the type of the value is not relevant until later - later being when the result is actually assigned to a variable of the Result type at which point the statically known type becomes dynamic.
It would be useful to be able to represent this "in-between" error value as being an error otherwise we always must know the full type at all times.
This becomes relevant in err itself that currently relies on type deduction of the result variable, a trick that only works in limited contexts.
A good example of this problem is or which cannot be combined with the self-deducing constructors:
proc f(): Result[float, int] =
let v = Result[int, int].ok(42)
# err deduces the "current" type to be `Result[int, int]` based on the
# `result` variable rather than on the context in which it's being evaluated
# (in this case `or` with the `v` variable: the result of this operation should
# be a `Result[int, int]`)
let x = v or err(42)Some ideas for how this could be solved:
errwould use something else thanresultas a type source - how to inject that though?errwould return a magic type that converts toResultat the latest possible moment, automatically deducing T - since we know it's an error at this point, context can decide what T should be.- other solutions?
Metadata
Metadata
Assignees
Labels
No labels