Cosmin Ioniță
Cosmin Ioniță

Reputation: 4045

How can I convert the result of Text.Printf to String?

The result of Text.Printf is a variable of type PrintfType.

Is there a way to convert this result to String?

I want something like that: convertToString :: PrintfType -> String

I've searched everywhere but I can't find anything.

Upvotes: 0

Views: 179

Answers (1)

Thomas M. DuBuisson
Thomas M. DuBuisson

Reputation: 64740

The result of Text.Printf is a variable of type PrintfType.

No. PrintfType is a constraint on the type, not a type itself. Notice the instances of PrintfType provided by module Text.Printf are:

IsChar c => PrintfType [c]
(~) * a () => PrintfType (IO a)
(PrintfArg a, PrintfType r) => PrintfType (a -> r)

Is there a way to convert this result to String?

No conversion necessary, String ~ [Char] and there exists an instance IsChar Char. Thus, the constraint of PrintfType String is satisfied.

I want something like that: convertToString :: PrintfType -> String

That makes no sense since you're using PrintfType as a Type instead of a constraint.

Upvotes: 4

Related Questions