Let's say I have a function with the signature Result a aError, Result a bError -> Result a [DidNotMatch]???
How can I extend the possible errors by with both aError
and bError
? (This is a reduced example from a parser combinator thing I'm trying)
I haven't tried it, but I'd expect this to work:
Result a err, Result a err -> Result a [DidNotMatch]err
if you give it two Result
s with different error types, they should get unioned
aah, did not think of that, but that makes sense. thank you :)
Hmm, this does not quite work. When I write the following:
hardcoded : Str, (Str -> Parser b err) -> Parser b [ExpectedStr Str]err
hardcoded = \value, callback ->
@Parser \input ->
if Str.startsWith input value then
when Str.splitFirst input value is
Ok {after} ->
@Parser next = callback value
next after
Err NotFound -> crash "Did not find item that was just found"
else
ParseFailed (ExpectedStr value)
I get an error message that [ParseFailed [ExpectedStr Str], Parsed b Str]
and [ParseFailed err, Parsed b Str]
cannot be unified. If I instead use the signature
hardcoded : Str, (Str -> Parser b [ExpectedStr Str]err) -> Parser b [ExpectedStr Str]err
hardcoded = \value, callback ->
@Parser \input ->
if Str.startsWith input value then
when Str.splitFirst input value is
Ok {after} ->
@Parser next = callback value
next after
Err NotFound -> crash "Did not find item that was just found"
else
ParseFailed (ExpectedStr value)
this works, but seems wrong, since I am requesting that the callback might also return ExpectedStr Str
and I'm doubling up the type in the type signature
(the signature of Parser
is Parser a err := Str -> [Parsed a Str, ParseFailed err]
right now)
Last updated: Jul 05 2025 at 12:14 UTC