Haskell FormatM->;IO双

Haskell FormatM->;IO双,haskell,Haskell,我试图使用Test.Hspec.Formatters中的getRealTime函数返回一个双精度值(或IO双精度值,例如,我可以将该值打印到屏幕上): 下面是getRealTime定义: getRealTime :: FormatM Double getRealTime = do t1 <- liftIO getPOSIXTime t0 <- gets startTime return (realToFrac $ t1 - t0) newtype FormatM a =

我试图使用Test.Hspec.Formatters中的getRealTime函数返回一个双精度值(或IO双精度值,例如,我可以将该值打印到屏幕上):

下面是getRealTime定义:

getRealTime :: FormatM Double
getRealTime = do
  t1 <- liftIO getPOSIXTime
  t0 <- gets startTime
  return (realToFrac $ t1 - t0)

newtype FormatM a = FormatM (StateT (IORef FormatterState) IO a)
  deriving (Functor, Applicative, Monad, MonadIO)

谢谢

不幸的是,在当前版本的库(撰写本文时为1.9.5)中,您不可能执行您想要执行的操作。
Test.Hspec
库不导出
FormatM
构造函数,也不导出将
FormatM a
转换为
IO a
的任何方法

最近的函数是
Test.Hspec.Formatters.Internal
模块中的
runFormatM

有以下功能:

runFormatM :: Bool -> Bool -> Bool -> Integer -> Handle -> FormatM a -> IO a
runFormatM useColor produceHTML_ printCpuTime seed handle (FormatM action) = do
  time <- getPOSIXTime
  cpuTime <- if printCpuTime then Just <$> CPUTime.getCPUTime else pure Nothing
  st <- newIORef (FormatterState handle useColor produceHTML_ False 0 0 0 [] seed cpuTime time)
  evalStateT action st
runFormatM::Bool->Bool->Bool->Integer->Handle->FormatM a->IO a
runFormatM useColor produceHTML_uPrintCpuTime种子句柄(FormatM操作)=do
时间
runFormatM :: Bool -> Bool -> Bool -> Integer -> Handle -> FormatM a -> IO a
runFormatM useColor produceHTML_ printCpuTime seed handle (FormatM action) = do
  time <- getPOSIXTime
  cpuTime <- if printCpuTime then Just <$> CPUTime.getCPUTime else pure Nothing
  st <- newIORef (FormatterState handle useColor produceHTML_ False 0 0 0 [] seed cpuTime time)
  evalStateT action st