-- -- file: Bindings.lhs -- -- created: 11/11/96 by Andrew Rock. -- -- purpose: Defines the ADT Bindings, used to store expressions keyed by name. -- > module Bindings (Bindings, newBind, updateBind, lookupBind, printBind) where > import Expr > import BSTree > type Bindings = BSTree String Expr newBind is an empty table of bindings. > newBind :: Bindings > newBind = emptyBST updateBind stores a name-expression pair in the table. Replace > updateBind :: String -> Expr -> Bindings -> Bindings > updateBind = updateBST (\ a b -> a) lookupBind return the expression associated with a name or Undef if not found. > lookupBind :: String -> Bindings -> Expr > lookupBind n b > = case lookupBST n b of > Just e -> e > Nothing -> Undef printBind pretty prints the names and values. > printBind :: Bindings -> String > printBind = unlines . (map s) . flattenBST > where s (n,e) = n ++ " = " ++ showExpr e