Can anyone point me to an example of where an inspect ability has been implemented for an opaque type?
https://github.com/roc-lang/roc/blob/main/examples/inspect-logging.roc
https://github.com/roc-lang/roc/blob/main/examples/Community.roc
Or are you looking for an InspectFormatter
implementation, like https://github.com/roc-lang/roc/blob/main/examples/GuiFormatter.roc?
I probably should have posted this in the Http.send causes exits program early on 400 code thread for better context.
I don't know enough to ask my question effectively, but basically I want to implement a type which may vary its inspect behavior depending on certain conditions. IE:
ResponseBody := List U8 implements [Inspect]
# made up inspect function - no idea what this might look like in reality:
inspect : ResponseBody -> f where f implements InspectFormatter
inspect = \responseBody ->
when responseBody |> List.takeFirst 50 |> Str.fromUtf8 is
Ok str -> # inspect returns a string
Err _ -> # inspect returns the first 50 bytes
I'm thinking InspectFormatter is what I need to figure out here...
This example may help as well.
Sidenote; you'll need to wrap what you return in a Tag if you want to return multiple types, e.g. [TagStr Str, TagBytes (List U8)]
So i'm playing around with some code trying to get a custom Inspect ability for my opaque. I've written a toInspector
function, but the language server tells me that I have an illegal specialization for a non-opaque/structural type. I'm confused because my type is definitely defined as an opaque:
ResponseBody := List U8 implements [Inspect {toInspector: toInspector}]
The error message says its specialized for a List U8
. My toInspector code is as follows:
toInspector = \respBody ->
when respBody |> List.takeFirst 50 |> Str.fromUtf8 is
Ok strBody -> Inspect.inspect (String strBody)
Err _ -> Inspect.inspect (Bytes respBody)
Need to unwrap the opaque
You are using it as a List U8
directly in that function
\@ResponseBody respBody ->
Ahh, of course! 🤦🏻♂️
Anyone know what I should make of this error message?
thread '<unnamed>' panicked at crates/compiler/solve/src/specialize.rs:866:25:
lambda set region not resolved: (`42.IdentId(11)`, MemberSpecializationInfo { _phase: PhantomData<roc_can::abilities::Resolved>, symbol: `42.IdentId(11)`, specialization_lambda_sets: VecMap { keys: [1], values: [124] } })
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
crates/compiler/solve/src/specialize.rs:866
Not sure what it means by a lambda set 'region' here. It clearly is an issue with my specialization of Inspect/toInspector, but beyond that, I'm lost.
The code panics in the function find_opaque_specialization_ambient_function
, after matching opt_specialization
to Some(member_impl)
(not None
), and matching member_impl
to MemberImpl::Impl(spec_symbol)
not MemberImpl::Error
.
So it seems that there has been some success in matching my specialization to an ability in the ability store, but when trying to get the "specialized lambda set", something goes wrong.
These are the scary errors where I generally comment out code til it works and then slowly work myself back. Maybe try a few variants of similar code.
Oh boy lol. Duly note... :+1:
Last updated: Jul 05 2025 at 12:14 UTC