Created
September 19, 2019 03:55
-
-
Save bedekelly/52c4caa0ad744159d07b6ca6a929438a to your computer and use it in GitHub Desktop.
List monad (+alternative) for nondeterminism in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
toss = {"Fair": ["Heads", "Tails"], "Biased": ["Heads", "Heads"]} | |
@do | |
def coins(): | |
coin = yield ["Fair", "Biased"] | |
result = yield toss[coin] | |
_ = yield guard(result == "Heads") | |
return coin | |
# Probability of a biased coin, given you observed Heads, is 2/3. | |
assert coins() == ["Fair", "Biased", "Biased"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment