ЗП
Size: a a a
ЗП
ЗП
ЗП
ЗП
AK
X и Y тоже могли быть data, не только newtypeclass MyClass d c where fn ∷ c → d
data Foo d c = Foo { f1 :: c, f2:: d }
type FooE d = Exists (Foo d)
mkFooE :: forall d c. (MyClass d c) => Foo d c -> FooE d
mkFooE = mkExists
newtype DifferentFoos d = DifferentFoos (Map.Map String (FooE d))
data X = XZ | XW
data Y = YQ | YU
data F = FG | FH
instance myClassXF ∷ MyClass F X where fn _ = FG
instance myClassYF ∷ MyClass F Y where fn _ = FH
foos' ∷ DifferentFoos F
foos' =
let
fooA :: Foo F X
fooA = Foo { f1 : XZ, f2 : FG }
fooB :: Foo F Y
fooB = Foo { f1 : YQ, f2 : FH }
in
DifferentFoos
$ Map.insert "y" (mkFooE fooA)
$ Map.singleton "x" (mkFooE fooB)
data Bar w x y z = ..., где w x фиксированы, а y и z вариативны?ЗП
data Bar1 w x y z = Bar1 w x y z`
newtype Bar2 w x y = Bar2 (Exists (Bar1 w x y))
newtype Bar w x = Bar (Exists (Bar2 w x))
AK
data Bar1 w x y z = Bar1 w x y z`
newtype Bar2 w x y = Bar2 (Exists (Bar1 w x y))
newtype Bar w x = Bar (Exists (Bar2 w x))
Bar2 внутри ExistsAK
ЗП
forallnewtype Bar x y = Bar (forall r1. (forall z. (forall r2. (forall w. (x -> y -> z -> w) -> r2) -> r2) -> r1) -> r1)
ЗП
ЗП
ЗП
newtype Exists1 f = Exists1 (forall r. (forall a. f a -> r) -> r)но идея через
mkExists1 ∷ forall f a. f a -> Exists1 f
mkExists1 fa = Exists1 (\f -> f fa)
runExists1 ∷ forall f r. (forall a. f a -> r) -> Exists1 f -> r
runExists1 e (Exists1 f) = f e
unsafeCoerce типа быстрее работает что-лиAK
data Bar1 w x y z = Bar1 w x y z`
newtype Bar2 w x y = Bar2 (Exists (Bar1 w x y))
newtype Bar w x = Bar (Exists (Bar2 w x))
p
newtype Exists1 f = Exists1 (forall r. (forall a. f a -> r) -> r)но идея через
mkExists1 ∷ forall f a. f a -> Exists1 f
mkExists1 fa = Exists1 (\f -> f fa)
runExists1 ∷ forall f r. (forall a. f a -> r) -> Exists1 f -> r
runExists1 e (Exists1 f) = f e
unsafeCoerce типа быстрее работает что-лиЗП
ЗП
p
ЗП
ЗП