Skip to content

Add mapSearchT#6

Open
ocharles wants to merge 1 commit intoennocramer:masterfrom
circuithub:master
Open

Add mapSearchT#6
ocharles wants to merge 1 commit intoennocramer:masterfrom
circuithub:master

Conversation

@ocharles
Copy link
Contributor

No description provided.

@ocharles
Copy link
Contributor Author

ocharles commented Aug 25, 2022

I think you could also depend on mmorph here if you wanted, but I went with a transformers-like solution. I want this change because I want to have part of my search operate in the monad SearchT c (Accum x) - the idea is I can map over a list, but look at my accumulated state and make sure I'm not trying something I've already tried in a different branch. This is slightly different to AccumT x (Search c), which would fork the accumulator at each branch.

Also, thank you for this terrific library. We're putting it to good use at circuithub.com! If you would like help maintaining this library, just let me know and I'll be more than happy to help.

@ocharles
Copy link
Contributor Author

ocharles commented Aug 25, 2022

Alas, I don't think this actually does what I want:

> runSearch $ evalAccumT ((lift (cost' (Sum 1)) >> add ['a'] >> look) <|> (lift (cost' (Sum 2)) >> add ['b'] >> look)) []
[(Sum {getSum = 1},"a"),(Sum {getSum = 2},"b")]

> runSearch $ mapSearchT (flip evalAccumT []) $ (cost' (Sum 1) >> lift (add ['a']) >> lift look) <|> (cost' (Sum 2) >> lift (add ['b']) >> lift look)
(Sum {getSum = 1},"a"),(Sum {getSum = 2},"b")]

I was hoping that the latter would have "ab" accumulated for both branches, but it dosen't seem to work how I think.

This does work:

> runAccum (runSearchT ((cost' (Sum 1) >> lift (add ['a']) >> lift look) <|> (cost' (Sum 2) >> lift (add ['b']) >> lift look))) []
([(Sum {getSum = 1},"a"),(Sum {getSum = 2},"ab")],"ab")

But I don't want to leave the Search monad. I imagine what I'll want is to instead produce a [Search c a] to see all branches taken instead.

Back to the drawing board!

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.

1 participant