无法从Context错误中推断出......

时间:2017-01-16 14:58:26

标签: haskell typeclass

我有以下两个模块,其中QueueAQueue的实例。

{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FlexibleContexts #-}

module Queue where

class Queue a b where
    empty :: a
    (|>) :: a -> b -> a
    null :: a -> Bool
    head :: a -> b
    tail :: a -> a
    toList :: a -> [b]
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FlexibleContexts #-}

module QueueA where 

import Queue

data QueueA b = QA {front :: [b], frontSize :: Int, rear :: [b], rearSize :: Int}

instance Queue (QueueA b) b where    

    empty = QA [] 0 [] 0

    (|>) (QA f fSize r rSize) el = norm $ QA f fSize (el : r) (rSize + 1)

    null (QA _ 0 _ 0) = True
    null _ = False

    head (QA a _ _ _) = Prelude.head a            

    tail (QA f fSize r rSize) = norm $ QA (Prelude.tail f) (fSize - 1) r rSize      

    toList (QA f _ r _) =  f ++ (reverse r)

它编译,但当我尝试使用空时我得到

Could not deduce (Queue a b0)
from the context (Queue a b)
  bound by the inferred type for ‘it’: Queue a b => a
  at <interactive>:113:1-5
The type variable ‘b0’ is ambiguous
When checking that ‘it’ has the inferred type
  it :: forall a b. Queue a b => a
Probable cause: the inferred type is ambiguous

现在我只是不知道为什么它无法确定元素的类型。 我需要改变什么?

0 个答案:

没有答案