algorithm - Haskell 中的 splitList 函数
问题描述
在我的作业中,有一个问题,我复制在下面。
编写一个函数 splitList ,它提供了将至少两个元素的列表拆分为两个非空部分的所有方法。类型声明为:
splitList :: [a] -> [([a],[a])]
电话splitList [1..4]
应给出:
Prelude> splitList [1..4]
[([1],[2,3,4]),([1,2],[3,4]),([1,2,3],[4])]
这是我写的代码:
splitList :: Eq a=> [a]->[([a],[a])]
splitList []=[([],[])]
splitList (x:xs) = [([x],xs)]++[(splitList xs)]
但它给出了一个错误:Couldn't match expected type `([a], [a])' with actual type `[([a], [a])]'
splitList (x:xs) = [([x],xs)]++[(splitList xs)]
我在错误突出显示的地方加粗。
解决方案
推荐阅读
- sql - 同时发生的事务会产生错误的选择结果
- java - 循环完成后程序未终止
- amazon-web-services - 在 S3 存储桶中授予公共读取权限时遇到问题
- tensorflow - 无法理解 keras.datasets.imdb
- big-o - 为什么在计算大 O 时 O(n*n*n!) 会简化为 O((n+2)!)
- python - 从 Python 中的多个列表中仅选择一个唯一元素
- pine-script - 如何从 Pine Script 中函数中断的循环中获取值?
- python - 使用 pip 在 Windows 中安装 ZeroMQ / pyzmq 时遇到问题
- python - 已安装 CUDA 但未使用 GPU
- java - How to find the first three strings, which start with a lower-case `a` in a sorted order