相关疑难解决方法(0)

Haskell范围和浮动

为什么浮点数的Haskell范围符号的行为与整数和字符的行为不同?

Prelude> [1, 3 .. 10] :: [Int]
[1,3,5,7,9] 
Prelude> [1, 3 .. 10] :: [Float]
[1.0,3.0,5.0,7.0,9.0,11.0]
Prelude> ['a', 'c' .. 'f']
"ace"
Run Code Online (Sandbox Code Playgroud)

如果最后一个元素接近上限,我会理解它,但这显然不是一个舍入问题.

floating-point haskell range-notation

42
推荐指数
2
解决办法
5368
查看次数

地图的结果列表是一个更长的

在这个Haskell示例中,结果有时比基本列表长一个.有什么线索吗?

Prelude> let x3 = [1,3..10]
Prelude> x3
[1,3,5,7,9]
Prelude> length x3
5
Prelude> length $ map (+1) x3
5
Prelude> length $ map (*3) x3
5
Prelude> length $ map (/2) x3
6
Prelude> length $ map (/1) x3
6
Prelude> length $ map (`div`1) x3
5
Prelude> map log x3
   [0.0,1.0986122886681098,1.6094379124341003
   ,1.9459101490553132,2.1972245773362196,2.3978952727983707]
Prelude> length it
6
Run Code Online (Sandbox Code Playgroud)

haskell

7
推荐指数
1
解决办法
82
查看次数

标签 统计

haskell ×2

floating-point ×1

range-notation ×1