简体   繁体   中英

`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? It fails to type-check if you replace Identity with say Int .
  • What is foreach keyword, and how does one use it in Haskell?

It's not a keyword, just an implicitly quantified type variable. It's like when you write a function

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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