私は現在、特定の方法で論理形式を取り決めているコードを書いています。このの追求では、私はレンズを使用する次のコード、書かれている:次に別のIsoからIsoを構築することについて混乱しています
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE Rank2Types #-}
module Logic.Internal.Formula where
import BasicPrelude hiding (empty, negate)
import qualified Data.Set as Set
import Control.Lens
data Atom = Pos { i :: Integer}
| Neg { i :: Integer}
deriving (Eq, Ord, Show, Read)
negatingAtom :: Iso' Atom Atom
negatingAtom = iso go go
where go (Pos x) = Neg x
go (Neg x) = Pos x
newtype Conjunction a = Conjunction (Set a)
deriving (Eq, Ord, Read, Show)
conjuncts :: Conjunction a -> [a]
conjuncts (Conjunction x) = Set.toList x
newtype Disjunction a = Disjunction (Set a)
deriving (Eq, Ord, Read, Show)
disjuncts :: Disjunction a -> [a]
disjuncts (Disjunction x) = Set.toList x
negatingClause :: Iso' (Conjunction Atom) (Disjunction Atom)
negatingClause = liftClause negatingAtom
type CNF = Conjunction (Disjunction Atom)
type DNF = Disjunction (Conjunction Atom)
-- Helper stuff
liftClause :: (Ord a) => Iso' a a -> Iso' (Conjunction a) (Disjunction a)
liftClause x = let pipeline = Set.fromList . fmap (view x) in
iso (Disjunction . pipeline . conjuncts) (Conjunction . pipeline . disjuncts)
を、私は自然な方法(私が信じたものを)に次のように記述することを試み:
type CNF = Conjunction (Disjunction Atom)
type DNF = Disjunction (Conjunction Atom)
negatingForm :: Iso' CNF DNF
negatingForm = liftClause negatingClause
しかし、型式チェッカーはであり、確かにでこれに満足していませんでした。正確な出力は以下の通りです:
Couldn't match type ‘Conjunction Atom’ with ‘Disjunction Atom’
Expected type: p1 (Disjunction Atom) (f1 (Disjunction Atom))
-> p1 (Disjunction Atom) (f1 (Disjunction Atom))
Actual type: p1 (Disjunction Atom) (f1 (Disjunction Atom))
-> p1 (Conjunction Atom) (f1 (Conjunction Atom))
In the first argument of ‘liftClause’, namely ‘negatingClause’
In the expression: liftClause negatingClause
私はレンズに少し新たなんだ、と本当に私が必要なIso
を実装する方法をだけでなく、私がここに誤解かを理解したいと思います。
おそらくあなたは 'liftClauseは::(オード、オードのB)=>イソ 'AB - >磯' したいです(接合詞a)(接頭辞b) 'となる。 –