Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Please explain type synonyms

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?

like image 932
akonsu Avatar asked Mar 19 '26 10:03

akonsu


1 Answers

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


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!