haskell-problem: io string -> [int]

前端 未结 4 1766
天涯浪人
天涯浪人 2021-01-18 00:18

Hello great programmers out there,

I\'m doing my first steps in haskell and have a function that confuses me:

import Data.List.Split
getncheck_guessl         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-18 00:58

    When you're writing a function that uses the IO monad, any value you want to return from the function must also be in the IO monad.

    This means that, instead of returning a value with type [Int], you have to return something with type IO [Int]. To do this, you use the return function, which "wraps up" the value into IO (it actually works for any monad).

    Just change the last line to wrap your value with return, like this:

    getncheck_guesslist = do
        line <- getLine
        let tmp = splitOneOf ",;" line
        return (map read tmp :: [Int])
    

提交回复
热议问题