{-# OPTIONS_GHC -fglasgow-exts #-}

module Interface (

  Interfaced(..),
  Interface(..),
  getInterface

) where

import Data.Typeable

import Control.Monad (msum)

class Typeable a => Interfaced a where
  interfaces :: a -> [Interface]
  interfaces = const []

data Interface = forall box . Typeable box => Interface box

getInterface :: (Interfaced a, Typeable interface) => a -> Maybe interface
getInterface = msum . (map checkInterface) . interfaces where
  checkInterface (Interface interface) = cast interface
