我有以下问题。我尝试使用 Gtk2Hs 和 Glade 在 Haskell 中为 BASE64 编码器创建一个简单的 GUI。这是 Haskell 中 BASE64 编码器的示例。
{-# LANGUAGE OverloadedStrings #-}
import Data.ByteString.Base64
import Data.ByteString.Char8
main = do
print $ unpack $ encode "Hello, world!"
print $ decode "SGVsbG8sIHdvcmxkIQ=="
现在我想为此示例创建 GUI,但我希望能够输入任何值进行编码。我已经创建了包含以下组件的模板: - entry1(输入要编码的值) - 按钮(开始生成) - entry2(查看生成的值)
我的哈斯克尔代码:
entry1 <- builderGetObject hello castToEntry "entry1"
entry2 <- builderGetObject hello castToEntry "entry2"
button <- builderGetObject hello castToButton "button"
onClicked button $ do
name2 <- get entry1 entryText
set entry2 [ entryText := unpack $ encode name2]
编译时收到以下错误
Couldn't match expected type `ByteString' with actual type `String'
In the first argument of `encode', namely `name2'
In the second argument of `($)', namely `encode name2'
In the second argument of `(:=)', namely `unpack $ encode name2'