本文介绍了为什么Haskell数字文字需要以数字开头和结尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在中,据说这是

这可能是什么其他用途?我无法想象任何这样的法律表达。

(为了阐明动机:我知道很多人写的数字像 9.0 0.7 所有时间不需要 ,但是我不能完全交好我自己。 0.7 而不是更紧凑但是没有更好的 .7 ,但被忽略的尾随零对我来说只是错误的,除非它们表达一些数量精确到十分之一,在Haskell使我写 9.0 - 数字的情况下很少出现这种情况。)



我忘了编写没有围绕空白的函数组合是合法的!这当然是可能的,但可以通过贪婪地解析浮动文字来避免这个问题,例如 replicate 3。 pred $ 8 ((replicate 3)。pred)8 replicate 3.pred $ 8 (replicate 3.0 pred)8



em> required 直接放在,没有空格的地方?

解决方案

其他用途的一个例子是点运算符(或其他任何以点开头或结尾的运算符): replicate 3.pred $ 8



另一个可能的用途是在范围表达式中: [1..10]



另外,你可以(几乎)总是写 9 而不是 9.0 ,因此避免了共计。

In The Haskell 98 Report it's said that

What other use might this be? I can't imagine any such legal expression.

(To clarify the motivation: I'm aware that many people write numbers like 9.0 or 0.7 all the time without needing to, but I can't quite befriend myself with this. I'm ok with 0.7 rather then the more compact but otherwise no better .7, but outwritten trailing zeroes feel just wrong to me unless they express some quantity is precise up to tenths, which is seldom the case in the occasions Haskell makes me write 9.0-numbers.)


I forgot it's legal to write function composition without surrounding whitespaces! That's of course a possibility, though one could avoid this problem by parsing floating literals greedily, such that replicate 3 . pred$8((replicate 3) . pred) 8 but replicate 3.pred$8(replicate 3.0 pred)8.


There is no expression where an integer literal is required to stand directly next to a ., without whitespace?

解决方案

One example of other uses is a dot operator (or any other operator starting or ending with a dot): replicate 3.pred$8.

Another possible use is in range expressions: [1..10].

Also, you can (almost) always write 9 instead of 9.0, thus avoiding the need for . altogether.

这篇关于为什么Haskell数字文字需要以数字开头和结尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 11:03