haskelliogtk2hs

Convert a entryGetText into Int gtk2hs


I'm trying to convert a entryText into a string, so I can use it for other functions.

`unsafePerformIO (entryGetText txtMagn)`

While trying to compile this code, I get the error message:

`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’`

Thanks in advance


Solution

  • This is because you wrote

    putStrLn unsafePerformIO (entryGetText txtMagn)
    

    Here you pass unsafePerformIO to putStrLn as a parameter. You actually meant:

    putStrLn (unsafePerformIO (entryGetText txtMagn))
    

    Now to the unsafePerformIO. As its name suggests, it is unsafe, so you'd better have a clear idea what are you trying to accomplish. To safely pull out your value out of the IO and use it later:

    text <- entryGetText txtMagn
    putStrLn text