相关疑难解决方法(0)

Haskell中匿名函数的真值表

我正在尝试为给定的布尔表达式生成真值表.我可以通过创建一个新的数据类型BoolExpr来做到这一点,但我想用匿名函数来做.它应该像这样工作:

> tTable (\x y -> not (x || y))
output:
F F | T
F T | F
T F | F
T T | F
Run Code Online (Sandbox Code Playgroud)

我的方法:

tbl p = [(uncurry p) tuple | tuple <- allval]
        where allval=[(x,y) | x <- [False,True], y <- [False,True]]
Run Code Online (Sandbox Code Playgroud)

这有效,但仅适用于2个参数.我想为任意数量的参数做这件事.所以我想我会创建一个从List获取Arguments的函数:

argsFromList f []     = f
argsFromList f (x:xs) = argsFromList (f x) xs
Run Code Online (Sandbox Code Playgroud)

这不起作用:

 Occurs check: cannot construct the infinite type: t = t1 -> t
   Expected type: t -> [t1] -> …
Run Code Online (Sandbox Code Playgroud)

logic haskell boolean truthtable

7
推荐指数
2
解决办法
706
查看次数

标签 统计

boolean ×1

haskell ×1

logic ×1

truthtable ×1