Skip to content

Instantly share code, notes, and snippets.

@timjb
Created August 28, 2014 15:50
Show Gist options
  • Save timjb/4b59a8254cc89a67311b to your computer and use it in GitHub Desktop.
Save timjb/4b59a8254cc89a67311b to your computer and use it in GitHub Desktop.
Bounded Existential types in Haskell
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ConstraintKinds #-}
module BoundedExistentials where
import GHC.Exts (Constraint)
class Constraint1 c where
type Constr1 c a :: Constraint
data SerializableC
instance Constraint1 SerializableC where
type Constr1 SerializableC a = (Read a, Show a)
data Any c k = forall s. c s => Any (k s)
data Any' c' k = forall s. Constr1 c' s => Any' (k s)
test :: Any' SerializableC []
test = Any' [1,2,3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment