Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.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
Elm中的值域表达式_Elm - Fatal编程技术网

Elm中的值域表达式

Elm中的值域表达式,elm,Elm,Elm支持[1..100],但是如果我尝试['a'..'z'],编译器会给我一个类型不匹配(需要一个数字,得到一个字符)。有什么办法可以让它工作吗?只需创建一个数字范围并将其映射到字符: List.map Char.fromCode[97..122] 编辑,或作为功能: charRange:Char->Char->List Char charRange从到= List.map Char.fromCode[(Char.toCode from)…(Char.toCode to)] 字符范围'a''

Elm支持
[1..100]
,但是如果我尝试
['a'..'z']
,编译器会给我一个类型不匹配(需要一个数字,得到一个字符)。有什么办法可以让它工作吗?

只需创建一个数字范围并将其映射到字符:

List.map Char.fromCode[97..122]
编辑,或作为功能:

charRange:Char->Char->List Char
charRange从到=
List.map Char.fromCode[(Char.toCode from)…(Char.toCode to)]
字符范围'a''d'--['a'、'b'、'c'、'd']:列表字符
编辑,从elm 0.18及更高版本开始,List.range最终是一个函数:

charRange:Char->Char->List Char
charRange从到=

List.map Char.fromCode在Elm 0.18中删除了
[..]
语法,因此现在需要将
[a..b]
的任何实例替换为
List.range a b
。请注意,
List.range
的类型是
Int->Int->List Int
,因此它也不适用于字符。