http://hackage.haskell.org/package/generics-mrsop comes with both a deep and a shallow encoding of datatypes.   

The paper is here: https://doi.org/10.1145/3240719.3241786

On Sat, Jan 26, 2019, 13:44 Marco Zocca <zocca.marco@gmail.com wrote:
Hi all,

 I'm a bit at a loss regarding this: say we have a value from a nested
algebraic type (definitions at the bottom)

testT2 :: T2
testT2 = T2 B (Left 42)

a generic encoding computed with `from` only goes one level deep,
leaving the sub-terms as they are :

λ> from testT2
SOP (Z (I B :* (I (Left 42) :* Nil)))

However, is it possible to recursively encode and collect all the
sub-terms, until primitive types or enumerations are encountered? The
encoded sub-terms from the example above are as follows:

λ> from B
SOP (S (Z Nil))
λ> from (Left 32 :: Either Int Char)
SOP (Z (I 32 :* Nil))

where

{-# language DeriveGeneric #-}
import qualified GHC.Generics as G
import Generics.SOP

data T1 = A | B | C deriving (G.Generic)
instance Generic T1

data T2 = T2 { t21 :: T1 , t22 :: Either Int Char } deriving (G.Generic)
instance Generic T2
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.