Skip to content

Traversal over immediate subexpressions and the embedded values#2302

Merged
Gabriella439 merged 5 commits intodhall-lang:masterfrom
mmhat:traverse-subexpressions-with
Sep 19, 2021
Merged

Traversal over immediate subexpressions and the embedded values#2302
Gabriella439 merged 5 commits intodhall-lang:masterfrom
mmhat:traverse-subexpressions-with

Conversation

@mmhat
Copy link
Collaborator

@mmhat mmhat commented Sep 18, 2021

This PR adds a variant of Dhall.Core.subExpressions which allows you to map over the embedded values simultaneously.
It is useful when you need to work with the AST directly. Specifically, it enables functions like:

traverseExpr :: Monad m => (Expr Src Void -> m (Maybe a)) -> Expr Src Void -> m (Expr Src a)
traverseExpr f expr = do
    mx <- f expr
    case mx of
        Nothing -> subExpressionsWith absurd (traverseExpr f) expr
        Just x -> pure $ Dhall.Core.Embed x

@Gabriella439 Gabriella439 merged commit ab64a9d into dhall-lang:master Sep 19, 2021
@mmhat mmhat deleted the traverse-subexpressions-with branch September 20, 2021 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants