gpt4 book ai didi

haskell - Haskell中的多个where语句有什么办法吗

转载 作者:行者123 更新时间:2023-12-03 15:10:44 25 4
gpt4 key购买 nike

我试图在一个函数中编写 3-4 where 语句,但我得到错误并且无法做到,我试图做这样的事情:

foo x=
| x == foo1 = 5
| x == foo2 =3
| x == foo3 =1
| otherwise =2
where foo1= samplefunct1 x
foo2= samplefunct2 x
foo3= samplefunct3 x

我知道代码有点没用,但我写这个只是为了举例说明我的意思。

有没有人可以帮助我?提前致谢。

最佳答案

删除 =foo x 之后并缩进你的代码

foo x
| x == foo1 = 5
| x == foo2 =3
| x == foo3 =1
| otherwise =2
where foo1 = samplefunct1 x
foo2 = samplefunct2 x
foo3 = samplefunct3 x

你很好。

关于haskell - Haskell中的多个where语句有什么办法吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15740543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com