我尝试打印一个值(可显示的Person类型),然后将返回类型从IO ()
更改为IO Person
。
import qualified Data.Text as T
data Person = Person
{ firstName :: T.Text
, lastName :: T.Text
} deriving Show
writePerson :: Person -> IO Person
writePerson p = const p <$> print p
预期结果:
Person {firstName = "Maria", lastName = "do Rosario"}
实际结果:
Person {firstName = "Maria", lastName = "do Rosario"}
Person {firstName = "Maria", lastName = "do Rosario"}
答案 0 :(得分:0)
您正在ghci中运行它。第一行是对print
的调用的输出。第二行是解释器,它显示对writePerson
的调用的返回值。它们是相同的,因为您将p
和const
用作参数。