小编Jet*_*tze的帖子

在Haskell中将命题逻辑扩展到模态逻辑

我在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)

haskell modal-logic

7
推荐指数
1
解决办法
554
查看次数

标签 统计

haskell ×1

modal-logic ×1