我想解决以下问题 - 给定所有选择器(e^i_n)和一些布尔函数({f_1, f_2, f_n}
)枚举闭包中的n个参数的所有函数(在[f_1,f_2,.. f_n] )。Haskell布尔函数实现
所以,我实现了BooleanFunctionClass和existencial BooleanFunction类型。 他们是哈斯克尔的狂妄精神吗?
class BooleanFunctionClass a where
arity :: a -> Int
instance BooleanFunctionClass Bool where
arity _ = 0
instance BooleanFunctionClass a => BooleanFunctionClass (Bool -> a) where
arity f = arity (f True) + 1
data BooleanFunction = forall a. (BooleanFunctionClass a) => BooleanFunction a String
instance Show BooleanFunction where
show (BooleanFunction _ str) = show str
但我不知道如何实现选择(的n个参数函数,该函数返回第k个)。 我想要selector :: Int -> Int -> BooleanFunction
。有什么建议么?
PS。抱歉。我不知道,如何在Markdown中插入TeX。
将布尔函数建模为BooleanFunction {arity :: Int,f :: [Bool] - > Bool}'会更容易。 –
我会尝试这种方法,但它不是数学风格。 – KAction
你能举一个你想要它做什么的例子吗? – augustss