packages feed

hsmt-0.1.0.0: src/HSMT/Core/Expr.hs

-- | Untyped core expressions.
--
-- Core expressions are plain trees. They are produced by the typed API and by
-- front-ends, and are interned into a hash-consed DAG ('HSMT.Core.Term')
-- before solving.
module HSMT.Core.Expr
  ( Expr (..)
  , app
  , constant
  , symbols
  ) where

import qualified Data.Set as Set

import HSMT.Core.Op

-- | An operator applied to its arguments.
data Expr = App !Op [Expr]
  deriving (Eq, Ord, Show)

-- | Apply an operator to a list of arguments (no sort checking).
app :: Op -> [Expr] -> Expr
app = App

-- | A nullary operator.
constant :: Op -> Expr
constant op = App op []

-- | All uninterpreted symbols occurring in an expression.
symbols :: Expr -> Set.Set Symbol
symbols = go Set.empty
  where
    go acc (App op args) =
      let acc' = case op of
            Uninterpreted s -> Set.insert s acc
            _ -> acc
       in foldl go acc' args