From #beginners > Type variables implement two abilities?, can we make it so that you never have to specify where a implements Inspect.Inspect
.
Make this no longer an error:
» x : a -> Str
… x = \v -> Inspect.toStr v
── TYPE MISMATCH ───────────────────────────────────────────────────────────────
This 1st argument to toStr has an unexpected type:
5│ x = \v -> Inspect.toStr v
^
This v value is a:
a
But toStr needs its 1st argument to be:
val where val implements Inspect
All types always implement Inspect
, so it should never need to be specified.
I was thinking this probably could be special handling for Inspect.Inspect
.
Richard commented that there might be a smarter way to do this:
yeah I think if we expose
Inspect.inspect
as* -> f where f implements InspectFormatter
thenInspect.toStr
can be implemented in terms of that and we're good
@Ayaz Hafiz any thoughts on this?
Tbh I wouldn't do this
you could probably special case it but I'm pretty sure it would complicate the implementation
how often is this case going to come up? I think it's likely not that frequent. Adding a suggestion to the error message to add the ability constraint is probably enough.
* -> f where f implements InspectFormatter
would not work without punching a hole in the type system
you could probably special case it but I'm pretty sure it would complicate the implementation
Wouldn't be as simple as saying all type variable always implement inspect? Like just appending it to a list?
yes, but that's not a trivial thing. Every type starts off as a variable, so you would have to have the list for every variable.
Make sense. Then nvm.
A nice to have, but definitely not worth any sort of complexity cause it is trivial for an end user to fix and is only hit with type variables
Last updated: Jul 06 2025 at 12:14 UTC