Kinds (promoted types) are the "level-up" for phantom type parameters. For example instead of blind a and b phantom types
newtype MoneyAmount a b = MoneyAmount Rational
We can build awesome compile-time safe and clear code like this
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
data Owner = Merchant | Customer
data AccountKind = Debit | Credit
newtype MoneyAmount (a :: Owner) (b :: AccountKind) = MoneyAmount Rational
And then I want to use this newtype in my persistent models, for example
CustomerTransfer
customerId CustomerId
moneyAmount (MoneyAmount 'Customer 'Debit)
currencyCode CurrencyCode
uuid TransferUuid
But persistent TH code is failing with error like
/app/src/CoinsAgent/Data/Model.hs:25:3: error:
* Exception when trying to run compile-time code:
Invalid field type "MoneyAmount 'Customer" PSFail ('\'',"Customer")
CallStack (from HasCallStack):
error, called at ./Database/Persist/Quasi.hs:382:36 in persistent-2.9.2-3XKdI42in9fIZrbGu
vFI1Z:Database.Persist.Quasi
Code: persistFileWith lowerCaseSettings "config/model"
* In the untyped splice:
$(persistFileWith lowerCaseSettings "config/model")
|
25 | $(persistFileWith lowerCaseSettings "config/model")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Kinds (promoted types) are the "level-up" for phantom type parameters. For example instead of blind
aandbphantom typesWe can build awesome compile-time safe and clear code like this
{-# LANGUAGE DataKinds #-} {-# LANGUAGE KindSignatures #-} data Owner = Merchant | Customer data AccountKind = Debit | Credit newtype MoneyAmount (a :: Owner) (b :: AccountKind) = MoneyAmount RationalAnd then I want to use this newtype in my persistent models, for example
But persistent TH code is failing with error like