显示哈斯克尔的结果
我是Haskell的新手。
如何返回(x1,x2)并从我的代码中打印出来?
qqq x
| x < 0 x1 = mod (-x) 10
| 1 < x && x < 99 x1 = mod x 10
| x2 = mod x 10
I'm very new to haskell.
How can I return (x1,x2) and print it out from my code?
qqq x
| x < 0 x1 = mod (-x) 10
| 1 < x && x < 99 x1 = mod x 10
| x2 = mod x 10
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您以错误的方式使用守卫。您似乎将它们视为
如果
语句,则可以将其用于 atsignement 。在Haskell中,您不将分配值为变量,您 neclare 这些。您可以使用:因此,每个后卫在方程符号之前都有条件(
=
),在右侧,返回了2件托盘,将第一个项目返回x1 ,作为第二项
x2
。您还应该实现
x == 1
和x&gt; = 99
的额外案例。You are using guards the wrong way. You seem to see these as
if
statements, that you then can use for assignements. In Haskell, you do not assign values to a variable, you declare these. You can work with:Here each guard thus has a condition before the equation sign (
=
), and at the right side returns a 2-tuple with as first item an expression forx1
, and as second itemx2
.You should also implement extra case(s) for
x == 1
andx >= 99
, these are not covered by the two guards.