content: module Vehicle.Syntax.AST.Prog where
  
  import Control.DeepSeq (NFData)
  import Data.Foldable (traverse_)
  import Data.Serialize (Serialize)
  import GHC.Generics (Generic)
  import Vehicle.Syntax.AST.Decl (GenericDecl)
  
  --------------------------------------------------------------------------------
  -- Programs
  
  -- | Type of Vehicle internal programs.
  newtype GenericProg expr = Main
    { -- | List of declarations.
      declarations :: [GenericDecl expr]
    }
    deriving (Show, Functor, Foldable, Traversable, Generic)
  
  instance (NFData expr) => NFData (GenericProg expr)
  
  instance (Serialize expr) => Serialize (GenericProg expr)
  
  traverseDecls ::
    (Monad m) =>
    (GenericDecl expr1 -> m (GenericDecl expr2)) ->
    GenericProg expr1 ->
    m (GenericProg expr2)
  traverseDecls f (Main ds) = Main <$> traverse f ds
  
  traverseDecls_ ::
    (Monad m) =>
    (GenericDecl expr1 -> m b) ->
    GenericProg expr1 ->
    m ()
  traverseDecls_ f (Main ds) = traverse_ f ds
  
  filterDecls ::
    (GenericDecl expr -> Bool) ->
    GenericProg expr ->
    GenericProg expr
  filterDecls f (Main ds) = Main (filter f ds)
  