所以我有一个函数 SolveEquasion,它返回一对 float*float[]。打印数字和数组并继续使用数组的最佳方法是什么?我编写了以下代码,但似乎有更好的方法
... |> SolveEquasion |> (fun (det, solution) -> printfn "Determinant = %f\nSolution = %A" det (Array.toList solution), solution ) |> snd
最佳答案
如果您想在管道中执行此操作,我认为您的解决方案不会得到改进。另一种方法是使用 let
绑定(bind),以及拆分流水线操作,以避免函数像 map
和 iter
.
let (det, solution) = SolveEquasion
printfn "Determinant = %f\nSolution = %A" det (Array.toList solution)
//do something else with solution
关于f# - 管道中的 printfn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5173390/