f# - 列表的递归除法 F#
问题描述
看来,我的递归函数需要帮助,它没有应用。我有一个例子,但我不明白我必须做什么。我的错误在哪里?我很乐意为您提供任何帮助!
我的功能:
let rec split = function
| [] -> ([],[])
| [x] -> ([x], [])
| x :: y :: tail -> split ((fun z -> z)(fun acc -> (x :: fst acc, y :: snd acc))) tail
let res = split [1; 2; 3; 4; 5]
printfn "%A" res
例子:
let rec split cont = function
| [] -> cont ([],[])
| [x] -> cont ([x], [])
| x :: y :: tail -> split (fun acc -> cont (x :: fst acc, y :: snd acc)) tail
let res = split (fun x -> x) [1; 2; 3; 4; 5]
printfn "%A" res
解决方案
我找到了...
let rec split = function
| x :: y :: xs -> let (xs1, xs2) = split xs in (x :: xs1, y :: xs2)
| [x] -> ([x], [])
| [] -> ([],[])
// let res = split [1; 2; 3; 4; 5]
// printfn "%A" res
推荐阅读
- ios - React Native App 未安装在 ios 模拟器中
- android - 当输入类型是android中的文本时如何在editText中隐藏下划线
- python - 通过 Jenkins 使用 FTP 将文件下载到远程服务器时出现权限被拒绝错误
- amazon-web-services - NAT 网关是否需要 Internet 网关?
- c# - Lucene.net 4.8 - IDE 不能识别 Lucene.Net.Standard 以及 StandardAnalyzer 的
- python - 无法在其他 PC 上运行转换后的 exe
- c# - 构造函数参数的自定义 Android.Gms.Maps.Model.TileProvider 问题
- highcharts - highchart:“分组类别” mutil 类别显示不漂亮
- indexeddb - 无法在“IDBObjectStore”上执行“放置”:函数(根)....更新...
... } 无法克隆 - php - 我正在玩测验,如果用户不在数据库中,我想创建新用户