Haskellには存在型というものがある。 これを使うとヘテロリストなどがつくれる例。
{-# LANGUAGE ExistentialQuantification #-}
data T = forall t. Mk t
xs :: [T]
xs = [Mk 42, Mk "answer"]
ここで疑問が浮かぶ。このデータ型はλ式にエンコードできるのか? ということだ。その方法は Rank2Types を使うことである。
{-# LANGUAGE Rank2Types #-}
type T a = (forall t. t -> a) -> a
mk :: a -> T b
mk x = \f -> f x
xs :: [T a]
xs = [mk 42, mk "answer"]