2016-11-18 67 views
2

我試圖做一個仿函數實例下列數據類型:類型不是多態的建議

data Event t a = Event { runEvent :: t -> ([a], Event t a) } 

instance Functor (Event t) where 
    fmap :: (a -> b) -> Event t a -> Event t b 
    fmap f e = Event go 
     where 
      go t = (fmap f x, e') 
       where 
        (x, e') = Event.runEvent e t 

但是編譯失敗,出現以下錯誤:

E FRP.fr:11: type `γ` is not as polymorphic as suggested in 
    the annotation where just `β` is announced. 
E FRP.fr:11: type error in expression go 
    type is : ([γ],Event α β) 
    expected: ([γ],Event α γ) 

我嘗試添加一些鍵入註釋來概括let綁定,但這不起作用。

回答

2

因此,我們必須進入e::Event t a

應用runEvente給我們依然在元組的第二個元素的Event t a,又何嘗不是如此?但它應該是Event t b,對吧?

(該錯誤是相當混亂,因爲它產生RESP。go,並使用已在類型檢查go被使用清爽型的變量)

+0

添加類型註釋去幫助。 –