开发者

Please explain type synonyms

开发者 https://www.devze.com 2023-04-01 18:49 出处:网络
I am learning so may be this is a trivial question. In the code generated by yesod scaffolding开发者_运维知识库 tool I found this expression:

I am learning so may be this is a trivial question.

In the code generated by yesod scaffolding开发者_运维知识库 tool I found this expression:

type YesodPersistBackend PersistTest = SqlPersist

My understanding is that it creates a parameterised type YesodPersistBackend that has one type argument PersistTest, and this is equivalent to the type SqlPersist.

Is this correct? If so, why would one create a type synonym with parameters for a type that does not have parameters?


This is not a vanilla type declaration. If you see the full code, it looks something like this -

instance YesodPersist PersistTest where
  type YesodPersistBackend PersistTest = SqlPersist

This is using an extension to Haskell98 called TypeFamilies. Read about this specific syntax here - http://www.haskell.org/ghc/docs/latest/html/users_guide/type-families.html#assoc-type-instance

0

精彩评论

暂无评论...
验证码 换一张
取 消