F# 是否与 Haskell 的看法等效? [英] Does F# have an equivalent to Haskell's take?

查看:20
本文介绍了F# 是否与 Haskell 的看法等效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 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 List.toSeq first. (Update: Apparently from the comments, this isn't necessary.)

这篇关于F# 是否与 Haskell 的看法等效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆