如何对无限列表使用任意值?
我有以下帮助功能:
-- Generator for variable names
instance Arbitrary VarName where
arbitrary = VarName <$> elements ["A", "B", "_0", "_"]
用于以下任务: “定义一个函数 freshVars :: [Varname],它为您提供以下模式的无限变量名称列表:
[VarName "A",...,VarName "Z",VarName "A0",...,VarName "Z0",VarName “A1”,…,VarName“Z1”,…]”
我该怎么做?我想我没有正确理解任意性。
i have the following help function:
-- Generator for variable names
instance Arbitrary VarName where
arbitrary = VarName <gt; elements ["A", "B", "_0", "_"]
for the following task:
"Define a function freshVars :: [Varname], which gives you an infinite list of variablenames in the following pattern:
[VarName "A",…,VarName "Z",VarName "A0",…,VarName "Z0",VarName "A1",…,VarName "Z1",…]"
How can i do this? i think i dont understand arbitrary properly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们可以使用
["", "0", "1", …, "9", "10", "11", …, "99", …]
创建一个列表:有了这个,我们就可以创建一个列表理解,它将构造带有前缀
Char
acter 的字符串,该字符将枚举['A' .. 'Z']
并使用其中一项 后缀。我们可以通过列表理解来做到这一点:我将填写
…
部分作为练习。We can make a list with
["", "0", "1", …, "9", "10", "11", …, "99", …]
with:Now that we have that, we can make a list comprehension that will construct strings with a prefix
Char
acter that will enumerate over['A' .. 'Z']
and uses one of the items of the suffix. We can do that with list comprehension:where I leave filling in the
…
parts as an exercise.