Data.Exists
使い方
purs(hs)newtype ShowBox' a = SB { value :: a, show :: a -> String }
newtype ShowBox = ShowBox (Exists ShowBox')
普通の書き方でいったん ShowBox' a
を定義しておいてから、 Exists ShowBox'
で本命を作る
こういう気持ちで読めばいい
purs(hs)newtype ShowBox = ShowBox (exsits a. a)
あるいは
purs(hs)newtype ShowBox = ∀ a. ShowBox a
これはまさにHaskellの
存在型の定義の仕方

実装
purs(hs)type role Exists representational
mkExists :: forall f a. f a -> Exists f
mkExists = unsafeCoerce
runExists :: forall f r. (forall a. f a -> r) -> Exists f -> r
runExists = unsafeCoerce
いろいろ見どころがある

mkExists
の型
runExistsの型
forall
を二重に使っている
purs(hs)data GosubF f a b = GosubF (Unit -> Free f b) (b -> Free f a)
data Free f a
= Free (Either a (f (Free f a)))
| Gosub (Exists (GosubF f a))