置换haskell
我有一个Haskell工作,要求我使用之前写过的其他两个功能编写置换函数,这两个功能正常工作,但我不知道如何将这些2连接到PERM功能,我该如何执行这?
prepend :: Num a => a -> [[a]] -> [[a]]
prepend a l = map (a :) l
delete :: Eq a => a -> [a] -> [a]
delete x [] = []
delete x (y:ys)
| x == y = delete x ys
| otherwise = y : delete x ys
perm的声明应为:perm :: num ad⇒[a]→[[a]]
我尝试的内容:
perm [] = [[]]
perm p = [prepend x xs | x <- p, xs <- perm (delete x p)]
I have a Haskell work which ask me to write a permutation function using 2 other functions prepend and delete I wrote before, those two functions works fine but I somehow don't know how to connect those 2 into the perm function, how can i do this?
prepend :: Num a => a -> [[a]] -> [[a]]
prepend a l = map (a :) l
delete :: Eq a => a -> [a] -> [a]
delete x [] = []
delete x (y:ys)
| x == y = delete x ys
| otherwise = y : delete x ys
The declaration of perm should be : perm :: Num a ⇒ [a] → [[a]]
What I tried:
perm [] = [[]]
perm p = [prepend x xs | x <- p, xs <- perm (delete x p)]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需使用
:
而不是prepend
。Just use
:
instead ofprepend
.