タイプPropは、命題文(または、より簡潔には、命題)をモデル化します。命題記号(変数)は、形式P(n)の項として符号化され、nは整数識別子である。 Interpr型は命題解釈を、命題記号ids(繰り返しなし)のScalaリストとして実装します。命題記号P(n)は、iがnである場合にのみ、解釈iにおいて真であることを意味する。スカラの命題論理
解釈iと命題pをとり、解釈が命題論理のセマンティクスに従って命題を満たすならば、Scalaブール値trueを返すScalaメソッド意味(i:Interpr、p:Prop)を書く。それ以外の場合はfalseを返します。
パターンマッチングと再帰を使用してこれを実装する方法は混乱します。どんな指導もいただければ幸いです!
// Example case
meaning(List(1,2), And(P(1), P(2))) is true
// Example case
meaning(List(1), And(P(1), P(2))) is false
type PVar = Int
type Interpr = List[PVar]
sealed abstract class Prop
case object True extends Prop
case object False extends Prop
case class P(id: PVar) extends Prop // propositional variable
case class Not(sub: Prop) extends Prop
case class Or(sub1: Prop, sub2: Prop) extends Prop // inclusive or
case class Xor(sub1: Prop, sub2: Prop) extends Prop // exclusive or
case class And(sub1: Prop, sub2: Prop) extends Prop
case class Impl(sub1: Prop, sub2: Prop) extends Prop // simple implication =>
case class Iff(sub1: Prop, sub2: Prop) extends Prop // double implication <=>
sealed abstract class Answer
case object Yes extends Answer
case object No extends Answer
def meaning(i: Interpr, p: Prop): Boolean = p match {
// solution here
}
"//ここに解決策"新しいオーバーレイは、あなたの宿題サービスです – pedrofurla
あなたの試したことや解決策について考えてみましょう。それは課題です、あなたはそれから学ぶことになっています。他の誰かの解決策を提出するだけのポイントは何ですか? –