Types 在SML数据类型中处理匿名函数

Types 在SML数据类型中处理匿名函数,types,sml,smlnj,currying,Types,Sml,Smlnj,Currying,我有以下数据类型和3个测试示例: datatype 'a test = Test of ('a -> bool) * string; val pos = Test (fn x => x > 0, "pos"); val even = Test (fn x => x mod 2 = 0, "even"); val small = Test (fn x => x < 100, "small"); 我假设您希望筛选给定输入通过的测试名称 您可以通过模式匹配分解测试

我有以下数据类型和3个测试示例:

datatype 'a test = Test of ('a -> bool) * string;
val pos = Test (fn x => x > 0, "pos");
val even = Test (fn x => x mod 2 = 0, "even");
val small = Test (fn x => x < 100, "small");

我假设您希望筛选给定输入通过的测试名称

您可以通过模式匹配分解测试,获得相应的函数并在当前输入上测试它们:

fun pass x [] = []
  | pass x (Test(f, s)::t) = if f x then s::pass x t 
                             else pass x t
fun pass x [] = []
  | pass x (Test(f, s)::t) = if f x then s::pass x t 
                             else pass x t