2014-06-06 61 views
0

我想使用getRealTime功能從Test.Hspec.Formatters返回一個Double值(或IO雙 - 東西,我可以打印到屏幕爲例):FormatM - > 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) 

我要尋找一個實現此的代碼示例:

getTime :: FormatM Double -> IO Double 

感謝

回答

1

不幸的是,你想要做的是不可能與當前版本的庫(1.9.5在寫作時)。 Test.Hspec庫不會導出FormatM構造函數,也不會導出將FormatM a轉換爲IO a的任何方法。

最接近的功能是runFormatMTest.Hspec.Formatters.Internal模塊中:

有功能:

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 

但是它不被封裝使得它不可訪問暴露。

相關問題