I am looking for a way to turn an SInt16
into an SString
. For my use case, it is enough that it does the right thing for concrete values, ie I will only be looking at the SString
result for concrete SInt16
s.
I noticed there is a Show
instance for SInt16
, which (of course) returns a String
. It is almost good enough for my needs: for symbolic values, it returns "<symbolic>:: SInt16"
and for concrete values eg 42, it returns "42:: SInt16"
. So if not for that pesky type tag, I could use literal. show @SInt16
literal. show @SInt16
as my SInt16 -> SString
function.
Is there a better way than editing the return value of show
to cut out the type tag?
Something like this should do the trick:
import Data.SBV
import Data.SBV.String
toString :: (SymVal a, Show a) => SBV a -> SString
toString = literal . maybe "<symbolic>" show . unliteral
I get:
*Main> toString (2 :: SInt16)
"2" :: SString
*Main> toString (uninterpret "n" :: SInt16)
"<symbolic>" :: SString
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.