module Language.PureScript.Bridge.TypeInfo where
import Data.Text (Text)
import qualified Data.Text as T
import Data.Proxy
import Data.Typeable
type TypeBridge = TypeInfo -> Maybe TypeInfo
data TypeInfo = TypeInfo {
typePackage :: !Text
, typeModule :: !Text
, typeName :: !Text
, typeParameters :: ![TypeInfo]
} deriving (Eq, Show)
mkTypeInfo :: Typeable t => Proxy t -> TypeInfo
mkTypeInfo = mkTypeInfo' . typeRep
mkTypeInfo' :: TypeRep -> TypeInfo
mkTypeInfo' rep = let
con = typeRepTyCon rep
in TypeInfo {
typePackage = T.pack $ tyConPackage con
, typeModule = T.pack $ tyConModule con
, typeName = T.pack $ tyConName con
, typeParameters = map mkTypeInfo' (typeRepArgs rep)
}
flattenTypeInfo :: TypeInfo -> [TypeInfo]
flattenTypeInfo t = t : concatMap flattenTypeInfo (typeParameters t)
eqTypeName :: Text -> TypeInfo -> Bool
eqTypeName name = (== name) . typeName