The OverloadedStrings extension is an extension in Haskell that allows one to write a string literal, that can be converted implicitly to any type that implements the IsString type class.
Questions tagged [overloaded-strings]
16 questions
43
votes
2 answers
Restricting string literals to Text only
I'm aware that the OverloadedStrings language pragma wraps an implicit fromString around all string literals. What I'd like to do is not actually overload strings, but merely change their meaning so that they are always turned into Text, and…

Dan Burton
- 53,238
- 27
- 117
- 198
27
votes
1 answer
How do I get the OverloadedStrings language extension working?
I've enabled overloaded strings, but I can't get them to work:
$ cat overloadedstrings.hs
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
lazy :: BL.ByteString
lazy = "I'm a…

dave4420
- 46,404
- 6
- 118
- 152
17
votes
1 answer
Using Overloaded Strings
OverloadedStrings extension is really very useful, however it has some downsides.
Consider the following function definition:
someFunction :: ToJSSTring a => a -> IO ()
someFunction = js_function . toJSSTring
In this case when if I want to pass a…

Geradlus_RU
- 1,466
- 2
- 20
- 37
9
votes
1 answer
Why does IsList require toList?
When using -XOverloadedStrings you can implement IsString which only requires a function fromString.
Now if you want to use string literals for pattern matching, you also have to implement Eq, which makes sense:
f :: MyString -> Bool
f "foo" =…

theo
- 305
- 2
- 7
7
votes
2 answers
Why am I getting this warning from GHCi?
I'm getting a curious warning when pattern matching, but only when OverloadedStrings is enabled...
$ ghci -Wall
GHCi, version 6.12.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp…

dave4420
- 46,404
- 6
- 118
- 152
5
votes
1 answer
Cannot use assign-op operators with overloaded objects nor string offsets
I have this portion of code and it gives me the error in the title.
I have a count $k from 1 to 5 for each table.
$myarray consists of at least 3 to 4 names.
The error occurs in the line with $qu .= ...
What i tried so far: changing the variablename…

little_fck
- 51
- 1
- 3
4
votes
2 answers
Why isn't ByteString converted automatically to FilePath?
I'm passing a (strict) ByteString to something expecting a System.IO.FilePath, which is declared as type FilePath = String. I'm also using {-# LANGUAGE OverloadedStrings #-}. I've had conversions in some places happen automatically, but here it does…

Matt Joiner
- 112,946
- 110
- 377
- 526
3
votes
1 answer
Utf8 and overloaded strings in Haskell
I realized that accents in my texts get converted to �.
I boiled it down, to the following example, which
writes (and overwrites) the file test.txt.
It uses exclusively methods from Data.Text, which are supposed
to handle unicode texts. I checked…

mna
- 263
- 2
- 8
2
votes
1 answer
M.Map sudden expected type error
Everything was working great up until about a month or so ago...
Suddenly I'm getting
berkson.github.io/source/blog.hs: 333, 42
• Couldn't match type ‘unordered-containers-0.2.7.1:Data.HashMap.Base.HashMap
…

Berkson
- 65
- 4
1
vote
1 answer
Haskell using OverloadedStrings, but getting [Char] error anyway
I understand from questions like this and this that using the PRAGMA OverloadedStrings means I should be able to use Text as my string-type.
However, as I test out my data types with Text, I get the following error:
$ stack ghci
Prelude> :l…

Mittenchops
- 18,633
- 33
- 128
- 246
1
vote
1 answer
Type error for Query string with postgresql-simple
Related to this question, I have a query template that I've constructed using the interpolate package, which I'm then trying to pass to the query_/execute_ functions from postgresql-simple. But the compiler refuses, with the the error
•…

user4601931
- 4,982
- 5
- 30
- 42
1
vote
1 answer
How to work with Regex and OverloadedString
I have been using Text.Regex.Posix in a file, everything works fine so far.
Now, I would like to use OverloadedStrings for something else but in the same file. The problem is when I activate OverloadedString all the code related to regex doesn't…

mb14
- 22,276
- 7
- 60
- 102
0
votes
1 answer
I am trying to send light sensor data to a microprocessor and getting "call of overloaded 'print(const char[19],unsigned int&)' is ambiguous" error
I have stored light sensor values in comb1, as an array in an unsigned int. I am trying to send these values to a microprocessor. The values are taken from a sensor stored in an array. Then I am trying to send the commands through this:
for(int i =…

Ivickt
- 29
- 5
0
votes
1 answer
How can I set OverloadedStrings in an ihaskell notebook?
I understand from the sample notebook that I should be able to enable and disable extensions as follows:
-- We can disable extensions.
:ext NoEmptyDataDecls
data Thing
:1:1: error:
• ‘Thing’ has no constructors (EmptyDataDecls…

Mittenchops
- 18,633
- 33
- 128
- 246
0
votes
1 answer
How do I get Rid of this error main.cpp:43:19: error: no viable overloaded '=' novowels[100] = remove(name[100]);
Your program must contain a function to remove all
the vowels and a function to determine whether a
character is a vowel. I keep recieveing this error
main.cpp:43:19: error: no viable overloaded '=' novowels[100] = remove(name[100]); *
*
*…