F# 是否与 Haskell 的看法等效? [英] Does F# have an equivalent to Haskell's take?
问题描述
在 Haskell 中,有一个函数take n list",它返回列表中的前 n 个元素.例如,sum (take 3 xs)"对列表 xs 中的前三个元素求和.F# 有等价物吗?我希望它是 List 函数之一,但我找不到任何似乎匹配的东西.
In Haskell, there is a function "take n list" which returns the first n elements from a list. For example "sum (take 3 xs)" sums up the first three elements in the list xs. Does F# have an equivalent? I expected it to be one of the List-functions, but I can't spot anything that seems to match.
推荐答案
是的,它叫做 Seq.take
.用法似乎与 Haskell 的相同:Seq.take
count source.要在列表中使用它,请使用 (更新:显然从评论来看,这不是必需的.)List.toSeq
首先.
Yeah, it's called Seq.take
. Usage seems to be identical to Haskell's: Seq.take
count source. To use it on a list, use (Update: Apparently from the comments, this isn't necessary.)List.toSeq
first.
这篇关于F# 是否与 Haskell 的看法等效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!