So, as the error states, we need to somehow move the stringRep
resolution into another postponed section. To achieve this we can instantiate an intermediate object, which introduces this section in its apply
function:
def resolve
[ a ]
( implicit someTypeResolver: SomeTypeResolver[ a ] )
=
new {
def apply( implicit stringRep: StringRep[ someTypeResolver.SomeType ] ) =
stringRep.string
}
assert( resolve[ Int ].apply == "I'm a bool" )
assert( resolve[ Char ].apply == "I'm a string" )
It must be noted that with this approach, the user must explicitly call the apply
function as shown in the assertions above.