overloaded-strings

Using Overloaded Strings

痴心易碎 提交于 2020-01-01 04:45:09
问题 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 literal value I have to add a type signature explicitly when OverloadedStrings is enabled: someFunction ("This is plain string" :: String) someFunction ("And this one is Text" :: Data.Text.Text) The reason for this necessity is quite obvious, I

Restricting string literals to Text only

拜拜、爱过 提交于 2019-12-31 11:00:10
问题 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 therefore, using a string literal as a list of characters should result in a type error. It appears to be impossible to import the IsString class without also importing the String instance for that class. Does ghc provide some way for me to restrict

M.Map sudden expected type error

柔情痞子 提交于 2019-12-18 09:08:32
问题 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 text-1.2.2.1:Data.Text.Internal.Text aeson-0.11.2.0:Data.Aeson.Types.Internal.Value’ with ‘M.Map [Char] [Char]’ Expected type: M.Map [Char] [Char] Actual type: Metadata • In the first argument of ‘(M.!)’, namely ‘md’ In the first argument of ‘(++)’, namely ‘(md M.! "author")’ In the second

How do I get the OverloadedStrings language extension working?

末鹿安然 提交于 2019-12-05 08:50:14
问题 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 lazy ByteString" strict :: B.ByteString strict = "I'm a strict ByteString" $ ghci GHCi, version 6.12.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading

Using Overloaded Strings

我们两清 提交于 2019-12-04 01:47:12
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 literal value I have to add a type signature explicitly when OverloadedStrings is enabled: someFunction ("This is plain string" :: String) someFunction ("And this one is Text" :: Data.Text.Text) The reason for this necessity is quite obvious, I suppose OverloadedStrings was designed to ease the passing of literal values to functions that have strict

How do I get the OverloadedStrings language extension working?

半世苍凉 提交于 2019-12-03 22:10:41
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 lazy ByteString" strict :: B.ByteString strict = "I'm a strict ByteString" $ ghci GHCi, version 6.12.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> :l overloadedstrings.hs [1 of 1] Compiling Main (

Restricting string literals to Text only

a 夏天 提交于 2019-12-02 21:46:31
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 therefore, using a string literal as a list of characters should result in a type error. It appears to be impossible to import the IsString class without also importing the String instance for that class. Does ghc provide some way for me to restrict string literals to Text only? It's a little bit of overkill, but one solution is to combine