use*_*426 17 string haskell concat
我知道这听起来非常简单,但我没能将两个字符串组合成一个新字符串.
来自gtk条目的IO字符串"a"由提取
a <- (entryGetText text_field)
Run Code Online (Sandbox Code Playgroud)
目标是结合它:
newstring ="文字:"+ a
有什么想法可以实现吗?谢谢!
Don*_*art 26
使用字符串连接:
do a <- entryGetText text_field
let b = "Text:" ++ a
return b
Run Code Online (Sandbox Code Playgroud)
更简单:
do a <- entryGetText text_field
return $ "Text:" ++ a
Run Code Online (Sandbox Code Playgroud)
你也可以玩游戏:
("Text:" ++) <$> (entryGetText text_field)
Run Code Online (Sandbox Code Playgroud)
Pup*_*ppy 14
我相信在Haskell中,字符串连接运算符是++
.
非常时刻,你使用赋值操作符x <- expr
与expr :: m a
和m
为一些单子,x
不是一个m a
,而是一个a
.在您的情况下,变量a
具有类型String
而不是IO String
,因此您可以像在纯代码中那样连接它,例如"hello world " ++ a
.