module Data.GI.CodeGen.Type
( Type(..)
, BasicType(..)
, io
, ptr
, funptr
, con
, maybeT
) where
import Data.Typeable (TypeRep, mkTyConApp, typeOf, typeRepTyCon, mkTyCon3)
import qualified Data.Text as T
import Data.Text (Text)
import Data.GI.GIR.BasicTypes (Type(..), BasicType(..))
con :: Text -> [TypeRep] -> TypeRep
con "[]" xs = mkTyConApp listCon xs
where listCon = typeRepTyCon (typeOf [True])
con "(,)" xs = mkTyConApp tupleCon xs
where tupleCon = typeRepTyCon (typeOf (True, True))
con s xs = mkTyConApp (mkTyCon3 "GI" "GI" (T.unpack s)) xs
io :: TypeRep -> TypeRep
io t = "IO" `con` [t]
ptr :: TypeRep -> TypeRep
ptr t = "Ptr" `con` [t]
funptr :: TypeRep -> TypeRep
funptr t = "FunPtr" `con` [t]
maybeT :: TypeRep -> TypeRep
maybeT t = "Maybe" `con` [t]