Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Haskell中将字符与数字进行比较?_Haskell_Pattern Matching - Fatal编程技术网

如何在Haskell中将字符与数字进行比较?

如何在Haskell中将字符与数字进行比较?,haskell,pattern-matching,Haskell,Pattern Matching,我试图通过以下模式匹配来实现 [x| x <- "example string", x > 106] 而且显然不能将ord识别为有效的关键字。不是关键字,它是来自: 两者都返回: Prelude Data.Char> [x | x <- "example string", ord x > 106] "xmplstrn" Prelude Data.Char> filter ((106 <) .

我试图通过以下模式匹配来实现

[x| x <- "example string", x > 106]
而且显然不能将ord识别为有效的关键字。

不是关键字,它是来自:

两者都返回:

Prelude Data.Char> [x | x <- "example string", ord x > 106]
"xmplstrn"
Prelude Data.Char> filter ((106 <) . ord) "example string"
"xmplstrn"
Prelude Data.Char>[x | x 106]
“xmplstrn”

Prelude Data.Char>filter((106如果您要比较的数字是一个常量,您可以始终转到另一个方向:将该数字转换为字符常量,然后直接与您的字符进行比较:

filter (> 'j') "example string"

您需要从
数据导入
ord
。Char
ord
不是关键字,它是
数据.Char
模块中的函数。
import Data.Char(ord)

myExpr = filter ((106 <) . ord) "example string"
Prelude Data.Char> [x | x <- "example string", ord x > 106]
"xmplstrn"
Prelude Data.Char> filter ((106 <) . ord) "example string"
"xmplstrn"
filter (> 'j') "example string"