简体   繁体   English

Haskell 中的“foreach”

[英]`foreach` in Haskell

This code type-checks:此代码类型检查:

type T :: Type -> foreach (r :: Type) -> Type -> Type
data T k r a

type T' :: Type -> Type
type T' a = T a Identity a
  • Why is it that the compiler requires a type of kind Type -> Type (ie., Identity ) here?为什么编译器在这里需要一种类型Type -> Type (即Identity )? It fails to type-check if you replace Identity with say Int .如果将Identity替换为 say Int ,它将无法进行类型检查。
  • What is foreach keyword, and how does one use it in Haskell?什么是foreach关键字,如何在 Haskell 中使用它?

It's not a keyword, just an implicitly quantified type variable.它不是关键字,只是一个隐式量化的类型变量。 It's like when you write a function就像你写一个 function

foo :: [Int] -> foreach Bool -> Double
foo = undefined

main = print $ foo [1,2,3] (Just True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM