Can anyone explain why these both compile happily :
data A a b = A { a :: a, b :: b }
newtype B a = B (A a (B a))
newtype C = C (A Int C)
But I cannot create a similarly recursively defined types via type synonyms?
type B a = A a (B a)
type C = A Int C
Although obviously data B a = A { a :: a, b :: B a }
works just fine.
Is there any way to avoid dealing with that extra constructor X everywhere I want the type recursive? I'm mostly passing in accessor functions that pick out the b
anyways, so I'm mostly okay, but if an easy circumvention mechanism exists I'd like to know about it.
Any pragmas I should be using to improve performance with the specialized data type C? Just specialize stuff?
Any clever trick for copying between A a b
and A c d
defining only the a -> b
and c -> d
mapping without copying over the record twice? I'm afraid that A
's fields will change in future. Template Haskell perhaps?
C
without either pattern binding or writingunC (C a) = a
someplace?newtype C = C { unC :: A Int C }
do what you want?newtype
constructor in GHC you can remove it withunsafeCoerce
:)