OverloadedStrings Language Pragma
21 Mar 2017The OverloadedStrings
language pragma can be enabled either by passing the -XOverloadedStrings
switch to GHC or you can just add the following to the top of your Haskell source:
The OverloadedStrings
language pragma changes the way that literal strings identify themselves, in a way that favours performance. [Char]
is a rather cumbersome type to be used when dealing with something as primitive as a string.
The literal string "Hello, world"
now identifies as a call to the fromString
function out of the IstString
type class. You can define instances like so:
Now we just cast our strings to our type, and the fromString
functions are invoked for us: