I've been playing around with opaque types and was wondering how to unwrap them properly if I don't do it at the beginning of the function as in the tutorial example?
toStr : Username -> Str
toStr = \@Username str ->
str
I realised that I could unpack it with when ... is
like this:
toStr : Username -> Str
toStr = \username ->
when username is
@Username str -> str
But intuitively I was trying to unwrap it the same way as in the tutorial example also for non argument unwarpps. So my question is, am I doing it right or is there another way to get the value inside an opaque type?
that's the way to do it! Basically it's always through destructuring like that
either is fine, and you can also do:
@Username str = username
Thanks for your answer! Your example only works if you unwrap the argument directly, right?
I'm not sure if my example was clear, but from reading the docs I thought this would also be possible.
unwrappLater : Username -> Str
unwrappLater = \username ->
@Username username
But it does not work. It makes sense that it doesn't work, but I just wanted to share my experience and my intuition that my brain thought it could work.
ah gotcha! Yeah that's trying to wrap it a second time :big_smile:
Interesting. That would actually be the reverse wrap function
Jonas Schell has marked this topic as resolved.
Last updated: Jul 06 2025 at 12:14 UTC