我在Haskell中编写了一些用于建模命题逻辑的代码
data Formula = Prop {propName :: String}
| Neg Formula
| Conj Formula Formula
| Disj Formula Formula
| Impl Formula Formula
| BiImpl Formula Formula
deriving (Eq,Ord)
Run Code Online (Sandbox Code Playgroud)
但是,由于数据类型已关闭,因此没有自然的方法将其扩展到Modal Logic.因此,我认为我应该使用类来代替.这样,我可以在以后轻松地在不同的模块中添加新的语言功能.问题是我不知道如何写它.我想要像下面这样的东西
type PropValue = (String,Bool) -- for example ("p",True) states that proposition p is true
type Valuation = [PropValue]
class Formula a where
evaluate :: a -> Valuation -> Bool
data Proposition = Prop String
instance Formula Proposition where
evaluate (Prop s) val = (s,True) `elem` val
data Conjunction = …
Run Code Online (Sandbox Code Playgroud)