F#是否与Haskell相当? [英] Does F# have an equivalent to Haskell's take?
本文介绍了F#是否与Haskell相当?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
是的,它叫做 Seq.take
。用法看起来与Haskell相同: Seq.take
count source 。 要在列表中使用它,请使用 (更新:显然来自评论,这是没有必要的。) List.toSeq
。
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.
解决方案
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屋!
查看全文