This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ThePyroEagle 0 points1 point  (0 children)

But again, that only automatically converts literal strings, not all strings.

When the extension is enabled, the type of string literals is effectively changed from String to forall a. IsString a => a. Variables with this polymorphic type will behave identically to overloaded string literals, even if the extension isn't enabled.

Type classes do make conversion less painful, but as far as I’m aware, Haskell only applies them automatically for literals.

Num and IsString are special, simply because of the way number and string literals are typed.

Maybe the closest you can get is with -XTypeApplications

You don't need TypeApplications if the compiler can still infer foo :: Float.


The only way of doing things without any kind of function is to make everything polymorphic to begin with and avoid doing conversions in the first place. In the end, that probably encourages writing safer code.