私はバランスのとれたリストの定義をhaskellに書こうとしています。 QueueAは、バランスの取れたリストを持つキューする必要があります:インターフェイスキューキューにバランスの取れたリストがある。
module Queue where
class Queue a where
empty :: a
(|>) :: a -> a -> a
null :: a -> Bool
head :: a -> a
tail :: a -> a
toList :: a -> [a]
に基づいて
module QueueA where
import Queue
data QueueA a = QA [a] [a]
instance Queue (Queue a) where
empty = QA [] []
(|>) (QA a b) el = norm $ QA a (el : b)
head (QA a _) = Prelude.head a
tail (QA a b) = norm $ QA (Prelude.tail a) b
toList queue = Queue.head queue : Queue.tail queue
norm :: [a] -> [a]
norm [email protected](QA a b) = if (length a) >= (length b) then queue else QA (a ++ reverse b) []
私が正しくインタフェースを定義する方法が分からない、私は私が見つけた例を中心に、これをベース。ほとんどのエラーは、次のようになります。
Couldn't match expected type `a' with actual type `QueueA a1'
`a' is a rigid type variable bound by
the instance declaration
at C:\Users\kroll\Dropbox\WS 16.17\Moderne Funktionale Programmierung\Übung\Blatt 8\Code\Queue
私は空:: Aを定義することは、おそらく間違っていることを知っているが、空::キューaはどちらか動作しません。
代わりに、インスタンス宣言をキュー(QueueA)にするべきではありませんか? –