Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.
Hi, I'd like to use Textinstead of String, afaiu it's more performant. How can I create a "text literal" ? "\r\n" for instance is interpreted as a String, is there a special syntax or should I use pack ?
Text
String
Enable OverloadedStrings
OverloadedStrings
thank you
and is there a "read" equivalent for Text ?
(BTW, this means that string literals will have type IsString a => a, so if you get some "ambiguous" errors, just stick type annotation next to it)
IsString a => a
None that I know of - I tend to do something like slapping
read :: Read a => Text -> a read = Prelude.read . T.unpack
into custom Prelude module
ok
If writing production code, avoid read (as it is a partial function), and prefer readMaybe.
read
readMaybe
Or readEither (though the Left side of it is quite useless)
readEither
Left
Hi, I'd like to use
Text
instead ofString
, afaiu it's more performant. How can I create a "text literal" ? "\r\n" for instance is interpreted as a String, is there a special syntax or should I use pack ?Enable
OverloadedStrings
thank you
and is there a "read" equivalent for Text ?
(BTW, this means that string literals will have type
IsString a => a
, so if you get some "ambiguous" errors, just stick type annotation next to it)None that I know of - I tend to do something like slapping
into custom Prelude module
ok
thank you
If writing production code, avoid
read
(as it is a partial function), and preferreadMaybe
.Or
readEither
(though theLeft
side of it is quite useless)