作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
看起来 [1,2,3] 和 [1..3] 之间有一个奇怪的区别。
在下面使用 runghc 会打印出一个“True”,然后永远挂起:为什么? (我使用的是 ghc 7.8.3)
module Main where
import Data.Functor((<$>))
import Data.Time.Clock(DiffTime)
import Data.Binary(Binary(..), encode, decode, Get)
import Data.Int(Int64)
instance Binary DiffTime where
put x = put (truncate (x * 10^12) :: Int64)
get = ((/ 10^12) . fromIntegral) <$> (get :: Get Int64)
prop_getput_difftime :: DiffTime -> Bool
prop_getput_difftime x = x == ((decode . encode $ x) :: DiffTime)
explicit :: [DiffTime]
explicit = [1,2,3,4,5,6,7,8,9,10]
elipsis :: [DiffTime]
elipsis = [1..10]
main :: IO ()
main = do
print $ all prop_getput_difftime explicit
print $ all prop_getput_difftime elipsis -- diverges!
最佳答案
感谢#haskell 的otulp,原因如下:
Prelude> take 3 [1..2] :: [Data.Time.DiffTime]
[1s,1.000000000001s,1.000000000002s]
Enum
DiffTime
的实例
elipsis
这解决了问题:
elipsis = map fromIntegral ([1..10] :: [Int])
关于haskell - 为什么这个 Haskell 程序会出现分歧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27421598/
我有两个包含 40000 个样本的数据集。我想用 python 计算这两个数据集之间的 Kullback-Leibler 散度。在 python 中有什么有效的方法吗? 最佳答案 编辑: 好的。我发现
我正在尝试编译一个 .c 文件,用于处理 mMIPS 指令集中硬件中的裁剪,但是我似乎在“results=sfu1”行处收到错误“宏参数数量不一致” ' 当我尝试使用 lcc -o mips_mem.
这个正则表达式 /{(\w+)}/g 应该匹配大括号 {} 之间 的每个单词字符。相反,我在 Regex101 JavaScript engine 中得到了不同的结果和 Chrome 控制台。 Reg
我是一名优秀的程序员,十分优秀!