module Language.Haskell.Tools.Rewrite.Create.Types where
import Data.String (IsString(..), String)
import Language.Haskell.Tools.AST
import Language.Haskell.Tools.PrettyPrint.Prepare
import Language.Haskell.Tools.Rewrite.Create.Kinds (mkKindConstraint)
import Language.Haskell.Tools.Rewrite.Create.Names (mkUnqualName')
import Language.Haskell.Tools.Rewrite.Create.Utils
import Language.Haskell.Tools.Rewrite.ElementTypes
import qualified Name as GHC (Name)
mkForallType :: [TyVar] -> Type -> Type
mkForallType vars t = mkAnn ("forall " <> child <> " . " <> child) (UTyForall (mkAnnList (separatedBy " " list) vars) t)
mkTypeVar' :: GHC.Name -> TyVar
mkTypeVar' = mkTypeVar . mkUnqualName'
mkCtxType :: Context -> Type -> Type
mkCtxType ctx t = mkAnn (child <> " " <> child) (UTyCtx ctx t)
mkFunctionType :: Type -> Type -> Type
mkFunctionType at rt = mkAnn (child <> " -> " <> child) (UTyFun at rt)
mkTupleType :: [Type] -> Type
mkTupleType args = mkAnn ("(" <> child <> ")") (UTyTuple (mkAnnList (separatedBy ", " list) args))
mkUnboxedTupleType :: [Type] -> Type
mkUnboxedTupleType args = mkAnn ("(#" <> child <> "#)") (UTyUnbTuple (mkAnnList (separatedBy ", " list) args))
mkListType :: Type -> Type
mkListType = mkAnn ("[" <> child <> "]") . UTyList
mkParArrayType :: Type -> Type
mkParArrayType = mkAnn ("[:" <> child <> ":]") . UTyParArray
mkTypeApp :: Type -> Type -> Type
mkTypeApp ft at = mkAnn (child <> " " <> child) (UTyApp ft at)
mkInfixTypeApp :: Type -> Operator -> Type -> Type
mkInfixTypeApp left op right = mkAnn (child <> " " <> child <> " " <> child) (UTyInfix left op right)
mkParenType :: Type -> Type
mkParenType = mkAnn ("(" <> child <> ")") . UTyParen
mkTypeVar :: Name -> TyVar
mkTypeVar n = mkAnn (child <> child) (UTyVarDecl n noth)
mkKindedTypeVar :: Name -> Kind -> TyVar
mkKindedTypeVar n k = mkAnn (child <> child) (UTyVarDecl n (justVal (mkKindConstraint k)))
mkVarType :: Name -> Type
mkVarType = wrapperAnn . UTyVar
mkKindedType :: Type -> Kind -> Type
mkKindedType t k = mkAnn (child <> " :: " <> child) (UTyKinded t k)
mkBangType :: Type -> Type
mkBangType = mkAnn ("!" <> child) . UTyBang
mkLazyType :: Type -> Type
mkLazyType = mkAnn ("~" <> child) . UTyLazy
mkUnpackType :: Type -> Type
mkUnpackType = mkAnn ("{-# UNPACK #-} " <> child) . UTyUnpack
mkNoUnpackType :: Type -> Type
mkNoUnpackType = mkAnn ("{-# NOUNPACK #-} " <> child) . UTyNoUnpack
mkWildcardType :: Type
mkWildcardType = mkAnn "_" UTyWildcard
mkNamedWildcardType :: Name -> Type
mkNamedWildcardType = mkAnn ("_" <> child) . UTyNamedWildc
mkSpliceType :: Splice -> Type
mkSpliceType = mkAnn child . UTySplice
mkQuasiQuoteType :: QuasiQuote -> Type
mkQuasiQuoteType = mkAnn child . UTyQuasiQuote
mkPromotedIntType :: Integer -> Type
mkPromotedIntType i = mkAnn child $ UTyPromoted $ mkAnn (fromString $ show i) (UPromotedInt i)
mkPromotedStringType :: String -> Type
mkPromotedStringType i = mkAnn child $ UTyPromoted $ mkAnn (fromString $ show i) (UPromotedString i)
mkPromotedConType :: Name -> Type
mkPromotedConType = mkAnn child . UTyPromoted . mkAnn child . UPromotedCon
mkPromotedListType :: [Type] -> Type
mkPromotedListType
= mkAnn child . UTyPromoted . mkAnn ("[" <> child <> "]") . UPromotedList . mkAnnList (separatedBy ", " list)
mkPromotedTupleType :: [Type] -> Type
mkPromotedTupleType
= mkAnn child . UTyPromoted . mkAnn ("(" <> child <> ")") . UPromotedTuple . mkAnnList (separatedBy ", " list)
mkPromotedUnitType :: Type
mkPromotedUnitType = mkAnn child $ UTyPromoted $ mkAnn "()" UPromotedUnit
mkContext :: Assertion -> Context
mkContext = mkAnn (child <> " =>") . UContext
mkClassAssert :: Name -> [Type] -> Assertion
mkClassAssert n args = mkAnn (child <> " " <> child) $ UClassAssert n (mkAnnList (separatedBy " " list) args)
mkInfixAssert :: Type -> Operator -> Type -> Assertion
mkInfixAssert left op right = mkAnn (child <> " " <> child <> " " <> child) $ UInfixAssert left op right
mkImplicitAssert :: Name -> Type -> Assertion
mkImplicitAssert n t = mkAnn (child <> " :: " <> child) $ UImplicitAssert n t
mkTupleAssertion :: [Assertion] -> Assertion
mkTupleAssertion ass = mkAnn ("(" <> child <> ")") $ UTupleAssert $ mkAnnList (separatedBy ", " list) ass