小编cae*_*ar_的帖子

在Haskell中有多个where语句的方法吗?

我试图在一个函数中写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
Run Code Online (Sandbox Code Playgroud)

我知道代码有点无用,但我只是写了这个来举例说明我的意思.

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

syntax haskell where-clause guard-clause function-definition

15
推荐指数
3
解决办法
2万
查看次数