Persistent can only store ADTs that do not have child data. I.E. You can save the following:
data Tag = Leaf | Fork
But recursive structures like this cannot be saved without serializing it in JSON:
data Tree a = (Leaf a) | Fork (Tree a) (Tree a)
What you need to understand is that Persistent is a type persistence layer on top of the database, so you need to think about your schema in terms of what is efficiently stored in the database, and not in terms of what is convenient. Haskell Structural Structure .
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase| Tree parent TreeId Maybe value String deriving Show |]
This diagram will give you the equivalent of the following structure.
data Tree a = Value a [Tree a]
Thomas
source share