f# - 写匹配的更短的方法

标签 f#

我有一个返回元组的函数:

let rec pack l = 
            let combine = List.fold packFunction (' ',[], []) l
            match combine with 
                            | (_,b,a) -> b::a |> List.rev |> List.tail

有没有办法在不使用 match 语句的情况下提取元组的一部分?

即,id 喜欢在不使用匹配语句的情况下从 (_,b,a) 中获取 b 和 a

最佳答案

这样的?

let rec pack l = 
    let _,b,a = List.fold packFunction (' ',[], []) l
    b::a |> List.rev |> List.tail

您总是可以直接从元组中提取:

let a,b = (1,1)

let a,b = functionWhichReturnsTuple

关于f# - 写匹配的更短的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5736495/

相关文章:

F# 转发可选参数

silverlight - 添加图像 F#

f# - 可区分联合的运算符重载

c# - 函数式编程和解耦

f# - F#的隐藏特性

.net - MailboxProcessor 性能问题

F#:为什么脚本文件不能识别模块?

c# - 如何使功能更强大?

.net - 为什么我在 mono 上收到此消息? "warning FS0191: Could not determine highest installed framework version...".NET”

f# - 为什么 foldBack 不会执行与 fold 相同的副作用?