【发布时间】:2021-01-19 10:48:54
【问题描述】:
我是一个相对较新的 F# 程序员,似乎每次我在代码中修复一个问题时都会出现另一个问题,所以我的问题在转置递归函数内部,我想在其中运行 if-else 语句来检查输入是否实际上是否有效,但是这个错误,我不知道为什么或如何修复它。
我已经有一个问题和标题非常相似的问题,但是由于各种原因,我被告知要提出一个新问题而不是编辑旧问题。
type Result<'T,'TError> =
| Ok of 'T
| Error of 'TError
let isValidTBL list =
match List.map List.length list |> List.distinct |> List.length with
| 1 -> true
| _ -> false
let Column_1 list =
if List.exists List.isEmpty list then [] // return empty list
else
list |> List.map List.head
let Column_2 list =
if List.exists List.isEmpty list then
Error "empty value"
else
list |> List.map List.tail |> Ok
let rec transpose list = [
if (isValidTBL list = false) then Error "Invalid Table"
else
match list with
| []::list -> ()
| list ->
yield Column_1 list
yield! transpose (Column_2 list) ]
警告 FS0020:此表达式的结果类型为“Result”,并被隐式忽略。考虑使用 'ignore' 显式丢弃该值,例如'expr |> ignore' 或 'let' 将结果绑定到一个名称,例如'让结果 = expr'。
错误 FS0001:此表达式应具有类型
''列表列表'
但这里有类型
'结果'
提前致谢
【问题讨论】:
标签: list recursion error-handling f# type-conversion