例如,如果我有这些奇怪的类型:
{-# LANGUAGE TypeFamilies #-}
type family WeirdFamily a
type instance WeirdFamily () = Int
type instance WeirdFamily (a, b) = (a, WeirdFamily b)
Run Code Online (Sandbox Code Playgroud)
我可以WeirdFamily (Bool, (Char, ()))
通过键入以下内容来显示(例如在 GHCi 中)结果:
:t WeirdFamily (Bool, (Char, ()))
Run Code Online (Sandbox Code Playgroud)
到 GHCi?
rankN
从这里使用:
{-# LANGUAGE RankNTypes #-}\nrankN :: (forall n. Num n => n -> n) -> (Int, Double)\nrankN f = (f 1, f 1.0)\n
Run Code Online (Sandbox Code Playgroud)\n为什么做不到map rankN [negate]
?有什么方法可以让它成为可能吗?
我想我现在(大部分)理解了 RankNTypes,并且看到我可以同时执行rankN (+1)
和 rankN negate
。
(当我认为没有涉及任何问题时,为什么会map rankN [negate]
给出一个奇怪的错误?)Couldn\'t match type \xe2\x80\x98n\xe2\x80\x99 with \xe2\x80\x98Integer\xe2\x80\x99
Integer
另外,我刚刚检查过:t map rankN
。它给出了可怕的Couldn\'t match type \xe2\x80\x98a\xe2\x80\x99 with \xe2\x80\x98n -> n\xe2\x80\x99 because type variable \xe2\x80\x98n\xe2\x80\x99 would escape its scope. This (rigid, skolem) …