--- | Generates the \"load\" field for a single parameter.
---
--- There is custom handling, depending on how the parameter is
--- specified. For a 'Maybe' type parameter, we allow that it is not
--- present (via 'Utils.maybeFromObj'). Otherwise, if there is a
--- default value, we allow the parameter to be abset, and finally if
--- there is no default value, we require its presence.
-loadField :: OpParam -> Q (Name, Stmt)
-loadField (fname, qt, qdefa) = do
- let fvar = mkName fname
- t <- qt
- defa <- qdefa
- -- these are used in all patterns below
- let objvar = varNameE "o"
- objfield = stringE fname
- bexp <- if isOptional t
- then [| $((varNameE "maybeFromObj")) $objvar $objfield |]
- else case defa of
- AppE (ConE dt) defval | dt == 'Just ->
- -- but has a default value
- [| $(varNameE "fromObjWithDefault")
- $objvar $objfield $(return defval) |]
- ConE dt | dt == 'Nothing ->
- [| $(varNameE "fromObj") $objvar $objfield |]
- s -> fail $ "Invalid default value " ++ show s ++
- ", expecting either 'Nothing' or a 'Just defval'"
- return (fvar, BindS (VarP fvar) bexp)
-
-loadConstructor :: String -> [OpParam] -> Q Exp