顯然有點心不在焉,我寫了something like如下:何時(如果曾經)可以部分應用類型同義詞?
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE TypeFamilies #-}
class Foo f where
type Bar f :: *
retbar :: Bar f -> IO f
type Baz f = (Foo f, Eq f)
-- WithBar :: * -> (*->Constraint) -> * -> Constraint
type WithBar b c f = (c f, Bar f ~ b)
instance Foo() where
type Bar() =()
retbar = return
naim :: WithBar() Baz u => IO u -- why can I do this?
naim = retbar()
main = naim :: IO()
只有在編譯成功,我意識到這不是應該實際工作:Baz
被定義爲一個參數一個類型的同義詞,但我在這裏沒有直接的論據。當我嘗試類似的時候,通常GHC會吼我Type synonym ‘Baz’ should have 1 argument, but has been given none
。
現在,不要誤解我的意思:我真的很想寫這個,很容易看到它在這個特定的例子中如何工作(簡單的內聯WithBar
會產生簽名naim :: (Foo u, Bar u ~()) => IO u
,這當然罰款),但我不明白爲什麼它實際上就像這樣工作。這可能只是ghc-7.8.2
中的一個漏洞,允許這麼做嗎?
此行爲由[LiberalTypeSynonyms](https://downloads.haskell.org/~ghc/7.6.3/docs/html/users_guide/data-type-extensions.html#type-synonyms)啓用。特別是,在啓用它的情況下,編譯器會在檢查部分應用的類型同義詞之前展開所有類型同義詞。我猜猜,TypeFamilies或ContraintKinds中的一個意味着LiberalTypeSynonyms。 – user2407038 2015-04-05 22:36:43
@ user2407038奇怪的是,它們並不意味着它。 – 2015-04-05 22:39:31