无法使用 -interactive-print 在 ghci 中的每一行之后打印时间戳

Can't use -interactive-print to print timestamps after each line in ghci

我正在尝试在 ghci 中评估的每一行之后打印当前时间。到目前为止,这是我的代码:

module TimePrint (timePrint) where

import System.IO
import Data.Time

getTime :: IO String
getTime = do
    now <- getCurrentTime
    return (formatTime defaultTimeLocale "%T" now)

timePrint :: Show a => a -> IO ()
timePrint a = putStrLn $ show a ++ "\n" ++ getTime

我 运行 ghci 就像这样:ghci -interactive-print=TimePrint.timePrint TimePrint

我得到的错误是这样的:

TimePrint.hs:12:44:
    Couldn't match expected type ‘[Char]’ with actual type ‘IO String’
    In the second argument of ‘(++)’, namely ‘getTime’
    In the second argument of ‘(++)’, namely ‘"\n" ++ getTime’
Failed, modules loaded: none.

我认为这与 timePrint 不在 IO monad 中有关,但除此之外我一无所知。有任何想法吗?我希望 ghci 输出的每一行看起来像:

Prelude> 1+2
3
11:59:20
Prelude> 3+4
7
12:00:16

等等

timePrint a = do
   s <- getTime
   putStrLn $ show a ++ "\n" ++ s

++ 想要一个字符串,而不是 IO 操作。