The first attempt to replace "t-shirt#" <> tshow i <> "-" colour"
with "s"t-shirt#${i}-${colour}"
, I remove the tshow
in purpose to see of the implicite interpolation will work. I get the following error message
/home/max/Exp/test-interpolation/test/Handler/WHStocktakeSpec.hs:34:9: error:
• Could not deduce (Num a0)
arising from a type ambiguity check for
the inferred type for ‘skus’
from the context: (Num a, Enum a, IsString a2, IsString a3,
Interpolate a a2, Interpolate a3 a2)
bound by the inferred type for ‘skus’:
forall {a} {a2} {a3}.
(Num a, Enum a, IsString a2, IsString a3, Interpolate a a2,
Interpolate a3 a2) =>
[a2]
at /home/max/Exp/test-interpolation/test/Handler/WHStocktakeSpec.hs:(34,9)-(43,21)
The type variable ‘a0’ is ambiguous
These potential instances exist:
instance Num a => Num (Identity a)
-- Defined in ‘Data.Functor.Identity’
instance Num Int32 -- Defined in ‘GHC.Int’
instance Num Int64 -- Defined in ‘GHC.Int’
...plus 10 others
...plus 47 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the ambiguity check for the inferred type for ‘skus’
To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
When checking the inferred type
skus :: forall {a1} {a2} {a3}.
(Num a1, Enum a1, IsString a2, IsString a3, Interpolate a1 a2,
Interpolate a3 a2) =>
[a2]
In the second argument of ‘($)’, namely
‘do insertUnique $ Operator "John" "Smith" "Jack" True
let skus = ... ++ ...
mapM
(\ sku
-> rawExecute
"insert ignore into 0_stock_master (stock_id, long_description) values(?,?)"
$ map PersistText [sku, ....])
skus’
|
34 | ,"t-shirt-red"
| ^^^^^^^^^^^^^^^^^^^^^...
/home/max/Exp/test-interpolation/test/Handler/WHStocktakeSpec.hs:44:5: error:
• Ambiguous type variable ‘t0’ arising from a use of ‘mapM’
prevents the constraint ‘(Traversable t0)’ from being solved.
Probable fix: use a type annotation to specify what ‘t0’ should be.
These potential instances exist:
instance Traversable (Either a) -- Defined in ‘Data.Traversable’
instance Traversable Identity -- Defined in ‘Data.Traversable’
instance Traversable Down -- Defined in ‘Data.Traversable’
...plus 10 others
...plus 193 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In a stmt of a 'do' block:
mapM
(\ sku
-> rawExecute
"insert ignore into 0_stock_master (stock_id, long_description) values(?,?)"
$ map PersistText [sku, ""])
skus
In the second argument of ‘($)’, namely
‘do insertUnique $ Operator "John" "Smith" "Jack" True
let skus = ... ++ ...
mapM
(\ sku
-> rawExecute
"insert ignore into 0_stock_master (stock_id, long_description) values(?,?)"
$ map PersistText [sku, ....])
skus’
In a stmt of a 'do' block:
runDB
$ do insertUnique $ Operator "John" "Smith" "Jack" True
let skus = ... ++ ...
mapM
(\ sku
-> rawExecute
"insert ignore into 0_stock_master (stock_id, long_description) values(?,?)"
$ map PersistText [sku, ....])
skus
|
44 | $ map PersistText [sku, ""]
| ^^^^
Failed, one module loaded.
Ok there are only two errors but I even didn’t try to read them. It might not be different from normal OverloadedStrings related error, but in this case you have to deal with 3 types , the interpolated strings itself and the 2 “fragment”.
Also it is not clear how to force type , can I do "s{i :: Int}
or "s{@Int i}"
?
Ala PHP, ie s"name= $name"
shortcut for s"name=${name}"
. Allows bracket for expression as in s"name = ${capitalize name}"
It might be nitpicking but we are doing syntaxic sugar there and s"name =${name}"
is not much better than "name ="<>name
, compare the three
s"name=${name}"
"name="<>name
s"name=$name"