Haskell 将entryGetText转换为Int gtk2hs

Haskell 将entryGetText转换为Int gtk2hs,haskell,io,gtk2hs,Haskell,Io,Gtk2hs,我正在尝试将entryText转换为字符串,以便将其用于其他函数 `unsafePerformIO (entryGetText txtMagn)` 尝试编译此代码时,我收到错误消息: `Couldn't match type ‘IO a0 -> a0’ with ‘[Char]’ Expected type: String Actual type: IO a0 -> a0 Probable cause: ‘unsafePerformIO’ is appl

我正在尝试将entryText转换为字符串,以便将其用于其他函数

`unsafePerformIO (entryGetText txtMagn)`
尝试编译此代码时,我收到错误消息:

`Couldn't match type ‘IO a0 -> a0’ with ‘[Char]’
    Expected type: String
      Actual type: IO a0 -> a0
    Probable cause: ‘unsafePerformIO’ is applied to too few arguments
    In the first argument of ‘putStrLn’, namely ‘unsafePerformIO’`

提前感谢

这是因为你写了

putStrLn unsafePerformIO (entryGetText txtMagn)
这里您将
unsafePerformIO
作为参数传递给
putStrLn
。你的意思是:

putStrLn (unsafePerformIO (entryGetText txtMagn))
现在转到
unsafePerformIO
。顾名思义,它是不安全的,所以你最好弄清楚你想要实现什么。要安全地将您的值从
IO
中取出并在以后使用它,请执行以下操作:

text <- entryGetText txtMagn
putStrLn text

text要获取值,必须使用read函数:

val <- getLine
someFunctionWhichNeedsTheValue (read val ::Float) 
val