module MOO.Builtins.Common ( Builtin(..)
, defaults, booleanDefaults, maybeDefaults ) where
import MOO.Types
import MOO.Task
data Builtin = Builtin {
builtinName :: Id
, builtinMinArgs :: Int
, builtinMaxArgs :: Maybe Int
, builtinArgTypes :: [Type]
, builtinReturnType :: Type
, builtinFunction :: [Value] -> MOO Value
}
defaultOptions :: (Value -> a) -> [Value] -> [a] -> [a]
defaultOptions f = defaultOptions'
where defaultOptions' (v:vs) (_:ds) = f v : defaultOptions' vs ds
defaultOptions' [] ds = ds
defaultOptions' vs [] = map f vs
defaults :: [Value] -> [Value] -> [Value]
defaults = defaultOptions id
booleanDefaults :: [Value] -> [Bool] -> [Bool]
booleanDefaults = defaultOptions truthOf
maybeDefaults :: [Value] -> [Maybe Value]
maybeDefaults = flip (defaultOptions Just) (repeat Nothing)