YS
Size: a a a
YS
YS
YS
АГ
YS
АГ
YS
YS
АГ
YS
АГ
upcast
, super
и smash
, которые могут похожие структуры друг в друга переливать одной командой. Но это уже довольно сложная штукаYS
upcast
, super
и smash
, которые могут похожие структуры друг в друга переливать одной командой. Но это уже довольно сложная штукаАГ
YS
YS
ЗП
YS
YS
YS
class GConvertible (a :: * -> *) (b :: * -> *) where
gconvert :: a p -> b p
instance Coercible a b => GConvertible a b where
gconvert = coerce
instance
(GConvertible a b, GConvertible a1 b1) =>
GConvertible (a :*: a1) (b :*: b1)
where
gconvert (l :*: r) = (gconvert l) :*: (gconvert r)
instance
(GConvertible a b, GConvertible a1 b1) =>
GConvertible (a :+: a1) (b :+: b1)
where
gconvert (L1 l) = L1 (gconvert l)
gconvert (R1 r) = R1 (gconvert r)
instance
(GConvertible a b) =>
GConvertible (K1 x (a p)) (K1 x (b p))
where
gconvert (K1 a) = K1 (gconvert a)
instance
(GConvertible a b) =>
GConvertible (M1 x y a) (M1 x y b)
where
gconvert (M1 x) = M1 (gconvert x)
instance GConvertible V1 V1 where
gconvert = undefined
instance GConvertible U1 U1 where
gconvert = id
convert ::
(Generic a, Generic b, GConvertible (Rep a) (Rep b)) =>
a ->
b
convert = to . gconvert . from