Guarantees about shape of Generic's Rep

Alexey Khudyakov <[email protected]> Tue, 20 Apr 2021 20:39:33 +0300
Newsgroups gmane.comp.lang.haskell.glasgow.user
Message-ID <[email protected]>
Hi!

I have a question about guarantees that GHC provides about shape of generic
representation of data type. To be more concrete if we have two
single-constructor data types with N fields will their binary trees 
built from
(:*:) be balanced in same way? Same for (:+:) binary tree.

I want to use generics to write conversions between data types with same 
shape:

 > λ> data Foo = Foo Int Char deriving (Show,Generic)
 > λ> to . coerce . from $ Foo 1 'c' :: (Int,Char)
 > (1,'c')
 > λ> to . coerce . from $ Foo 1 'c' :: (Sum Int,Char)
 > (Sum {getSum = 1},'c')
 > λ> to . coerce . from $ (Sum (1::Int), 'c') :: Foo
 > Foo 1 'c'

Coercion between Reps for different types is only possible when they 
have same
shape. Quick experiments shows that they're same. I think that they 
should be
same but documentation is silent about this.


Thanks in advance,
Alexey
_______________________________________________
Glasgow-haskell-users mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users