【发布时间】:2023-02-06 00:47:09
【问题描述】:
所以我是 Haskell 的新手,下面我尝试编写一个函数,该函数采用给定的 e 值和给定的列表,并确定给定值是否出现在给定的列表中,如果给定的值确实出现则输出 True,否则输出 False。
inListm e [] = False
inListm e (x:xs)
| e == x = True || inListm e xs
| otherwise = False || inListm e xs
如果
inListm 2 [0, 2, 1, 2]
给出,输出将是
True
但是,我希望最终输出在这样的列表中
[True]
我试图通过
inListd e [] = False : []
inListd e (x:xs)
| e == x = True : [] || inListd e xs
| otherwise = False :[] || inListd e xs
但是给我的只是一个错误,所以我想知道如何解决这个问题
【问题讨论】: