如何在Haskell中返回一个元组

-3 haskell tuples

type Record=([Char],[Char],[Char],[Char],[Char])

createAccount::IO()->Record
createAccount=do
    putStrLn "Enter First Name"
    fname<-getLine
    putStrLn "Enter Last Name"
    lname<-getLine
    putStrLn "Enter State"
    state<-getLine
    putStrLn "Enter City"
    city<-getLine
    putStrLn "Enter House No."
    hnum<-getLine
    let hnumInt = read hnum :: Integer
    putStrLn "Enter Contact"
    contact<-getLine
    return (fname,lname,state,city,contact)
Run Code Online (Sandbox Code Playgroud)

Eri*_*ikR 5

错误消息是说类型签名createAccount实际上是:

createAccount :: IO ([Char],[Char],[Char],[Char],[Char])
Run Code Online (Sandbox Code Playgroud)

不像IO() -> Record你宣布的那样.

修复它的选项:

  • 更改类型签名IO ([Char],[Char],[Char],[Char],[Char])(或equivalenly: IO Record)
  • 删除类型签名 - 你不需要它,因为Haskell可以解决它.

  • *删除类型签名 - 你不需要它,因为Haskell可以解决它.*但是,为所有顶级绑定添加类型签名是很好的做法. (3认同)