0
내가 (M.lookup의 X 컨텍스트가) 아무것도없는 경우 오류가 발생하는 것을 시도하고
expand :: Expression -> [String] -> Context -> Expression
expand expr [] context = expr
expand expr (x:xs) context = expand (subst x newExp expr) xs context
where
(Just newExp) = (M.lookup x context)
이 코드 조각은 그렇게 할 수가 있어요
?
감사합니다.
expand expr [] context = Just expr
expand expr (x:xs) context = do
newExpr <- M.lookup x context
expand (subst x newExpr expr) xs context
이 대신 error
를 사용하여 오류를 던지는, 사용하기위한 방법 Maybe
, 당신은 단지 값을 반환하고 오류를보고하는 방법에 대한 나중에 결정할 수 있습니다 :