import Data.Kind data Box (c :: Type -> Constraint) = forall a. (c a) => MkBox a instance Animal (Box Animal) where noise (MkBox x) = noise x class Animal a where noise :: a -> String data Sheep = MkSheep data Cow = MkCow instance Animal Sheep where noise _ = "baaaaah!" instance Animal Cow where noise _ = "moooooo!" random_animal :: Double -> Box Animal random_animal n | n < 0.5 = MkBox MkSheep | otherwise = MkBox MkCow main :: IO () main = do let random_number = 0.234 let animal = random_animal random_number putStrLn (noise animal)