Why does rust use struct keyword?

Interestingly, you can encode the object type in Haskell like so:

{-# LANGUAGE ExistentialQuantification, KindSignatures, ConstraintKinds #-}

import Data.Kind

data Dyn (c :: * -> Constraint) = forall (t :: *). (c t :: Constraint) => D t

heteroList :: [Dyn Show]
heteroList = [D (), D 5, D True]

It might be interesting to add this type to the base package in Haskell or add some sugar for it; seems to me that Haskell could take a page from Rust here.

PS: Thanks for the fun and interesting discussion; and sorry for the OT on traits :wink:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.