Rei*_*ica 2 haskell dependent-type
此代码类型检查:
type T :: Type -> foreach (r :: Type) -> Type -> Type
data T k r a
type T' :: Type -> Type
type T' a = T a Identity a
Run Code Online (Sandbox Code Playgroud)
Type -> Type(即Identity)类型?Identity如果您替换为 say ,它无法进行类型检查Int。foreach关键字,在 Haskell 中如何使用它?它不是关键字,只是隐式量化的类型变量。就像你写一个函数一样
foo :: Int -> foreach r -> Double
foo = undefined
main = print ( foo 123 (Just 'w')
, foo 789 [False, True, False] )
Run Code Online (Sandbox Code Playgroud)
...soforeach r可以与Maybe Char或统一[Bool],但不能统一,例如Float。
现在,在您的示例中,情况更加奇怪,因为您还没有应用任何Identity内容。这意味着foreachin 的类型T a Identity a实际上似乎是s签名->中部分应用的运算符,提升了一级......时髦的东西。IdentityType -> Type
| 归档时间: |
|
| 查看次数: |
230 次 |
| 最近记录: |