Changeset 2812 for src/Pugs/Bind.hs
- Timestamp:
- 05/07/05 13:48:01 (4 years ago)
- svk:copy_cache_prev:
- 4340
- Files:
-
- 1 modified
-
src/Pugs/Bind.hs (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Bind.hs
r2774 r2812 15 15 import Pugs.Types 16 16 17 -- |Contains either a valid value of \'a\' (@Right@), or a @String@ error 18 -- message (@Left@). 17 19 type MaybeError a = Either String a 18 20 19 21 isRequired prm = not ( isOptional prm || isNamed prm ) 20 22 21 bindNames :: [Exp] -> [Param] -> (Bindings, [Exp], [Param]) 23 -- |Match up named arguments with named parameters, producing a list of new 24 -- bindings, and lists of remaining unbound args and params. 25 bindNames :: [Exp] -- ^ List of argument expressions to be bound 26 -> [Param] -- ^ List of parameters to try binding; includes both 27 -- named params and positional params 28 -> (Bindings, [Exp], [Param]) -- ^ Bindings made; remaining (unbound) 29 -- named args; remaining 30 -- (positional) params 22 31 bindNames exps prms = (bound, exps', prms') 23 32 where … … 80 89 [] -> internalError $ "bindEmpty: empty string encountered" 81 90 91 -- |Return @True@ if the given expression represents a pair (i.e. it uses the 92 -- \"=>\" pair composer). 82 93 isPair :: Exp -> Bool 83 94 isPair (Pos _ exp) = isPair exp … … 88 99 isPair _ = False 89 100 101 -- |Decompose a pair-constructor 'Exp'ression (\"=>\") into a Haskell pair 102 -- (@key :: 'String'@, @value :: 'Exp'@). 90 103 unPair :: Exp -> (String, Exp) 91 104 unPair (Pos _ exp) = unPair exp … … 97 110 98 111 -- performs a binding and then verifies that it's complete in one go 99 bindParams :: VCode -> [Exp] -> [Exp] -> MaybeError VCode 112 {-| 113 Bind parameters to a callable, then verify that the binding is complete 114 (i.e. all mandatory params are bound; all unspecified params have default 115 bindings). Uses 'bindSomeParams' to perform the initial binding, then uses 116 'finalizeBindings' to check all required params and give default values to 117 any unbound optional ones. 118 -} 119 bindParams :: VCode -- ^ A code object to perform bindings on 120 -> [Exp] -- ^ List of invocants to bind 121 -> [Exp] -- ^ List of arguments (actual params) to bind 122 -> MaybeError VCode -- ^ Returns either a new 'VCode' with all the 123 -- bindings in place, or an error message 100 124 bindParams sub invsExp argsExp = do 101 125 case bindSomeParams sub invsExp argsExp of … … 138 162 139 163 -- takes invocants and arguments, and creates a binding from the remaining params in the sub 164 {-| 165 Take a code object and lists of invocants and arguments, and produce (if 166 possible) a new 'VCode' value representing the same code object, with as many 167 parameters bound as possible (using the given invocants and args). 168 -} 140 169 bindSomeParams :: VCode -> [Exp] -> [Exp] -> MaybeError VCode 141 170 bindSomeParams sub invsExp argsExp = do
