有这样一种情况:
有一个功能
fn :: Bool -> Bool -> Bool -> Bool。有一个由函数参数的可能值列表组成的列表
fn:([[False, False, False], ... , [True, True, True]]由函数参数的数量生成)
我想在Python中实现类似“星号表达式”的东西:fn(*[a,b,...,z]) == fn(a,b,...,z)
并做这样的事情来获取所有“参数”列表的函数值:map (t $ fn) [[False, False, False], [True, True, True]]where t f [x,y,z] = f x y z.
问题是参数fn可能不是三个,而是或多或少。As 分别是 和 "argument" 列表中的元素。
如何实现一个函数t,以便它将具有可变数量元素的列表作为第二个参数?提前致谢!
编辑:
我达到了理想的解决方案,似乎:foldl a (\x -> \y -> \z -> z) [1,2,3]在哪里a = \f -> \x -> f x。让我们做一个 beta 减少:
a (\x -> \y -> \z -> z) 1==(\x -> (\t -> \y -> \z -> z) x) 1==\y -> \z -> za (\y -> \z -> z) 2==(\x -> (\y -> \z -> z) x) 2==\z -> za (\z -> z) 3==(\x -> (\z -> z) x) 3==3
但:
• Occurs check: cannot construct the infinite type: t0 ~ t0 -> t0
Expected type: (t0 -> t0 -> t0 -> t0) -> t0 -> t0 -> t0 -> t0 -> t0
Actual type: (t0 -> t0 -> t0 -> t0 -> t0)
-> t0 -> t0 -> t0 -> t0 -> t0
• In the first argument of ‘foldl’, namely ‘a’
In the second argument of ‘($)’, namely
‘foldl a (\ x -> \ y -> \ z -> z) [1, 2, 3]’
In the second argument of ‘($)’, namely
‘show $ foldl a (\ x -> \ y -> \ z -> z) [1, 2, 3]’
查德特?