Hey! I would like to know if there’s a non-“workaround” solution to a type checking issue I’m facing:
Imagine the following example function:
What I would like to do is to provide a default
argument to
.
Something like:
The above doesn’t compile because
is of type
rather than
.
Casting
to
makes it so that I can’t call
because there isn’t enough type information to infer that
is
(i.e. I would have to call
), which is a no-go.
The obvious “workaround” solution here is to create a second function that calls the first function with the my default
, i.e.:
However, is there any way to make this work without relying on a second function? I.e., by providing a default argument to the first version of the function? I played around with the
experimental directive but couldn’t get it to work. Am I missing something?
submitted by /u/YarnSphere
[link] [comments]