【发布时间】:2011-03-22 17:57:26
【问题描述】:
假设我有一个形状列表:
type shape =
| Circle of float
| Rectangle of float * float
let a = [ Circle 5.0; Rectangle (4.0, 6.0)]
然后我该如何测试,例如一个圆存在于一个?我可以为每个形状创建一个函数
let isCircle s =
match s with
| Circle -> true
| _ -> false
List.exists isCircle a
但我觉得在 F# 中必须有一种更优雅的方式,而不是必须为每种形状类型定义这样的函数。有吗?
相关问题是如何根据形状类型对形状列表进行分组:
a |> seq.groupBy( <shapetype? >)
【问题讨论】:
-
(略OT)这让我想起了code highlighting is supported for F#(!)
-
请参阅meta.stackexchange.com/questions/981/syntax-highlighting-hints SO 上没有特定于语言的突出显示。
标签: f#