Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add built-in support for Delay monad #263

Merged
merged 1 commit into from
Jan 17, 2024
Merged

Conversation

jespercockx
Copy link
Member

Currently there is no good way to define potentially-looping functions with agda2hs. We have the loop function in Haskell.Extra.Loop but it still requires a proof of termination if you want to use it on the Agda side. This PR adds support for the Delay monad to agda2hs, in a way that is completely transparent in the resulting Haskell code.

@jespercockx jespercockx requested a review from flupe January 15, 2024 17:35
@jespercockx jespercockx force-pushed the Delay branch 2 times, most recently from 85f1b49 to 57d6c4a Compare January 16, 2024 10:16
@jespercockx
Copy link
Member Author

Hm, I just realized this is not sound, since it is possible to distinguish between now and later in Agda. For example, one can write the following function:

bad : Delay a ∞  Bool
bad (now x) = True
bad (later x) = False

which would get compiled to

bad :: a -> Bool
bad x = True
bad x = False

which is, well, bad.

If we want to have actual support for delay, we should enforce somehow that the result is the same in both cases, or simply forbid pattern matching on Delay altogether.

@jespercockx
Copy link
Member Author

Perhaps we could allow a single function runDelay defined like this:

runDelay : {@0 x : a} (y : Delay a ∞)  @0 HasResult x y  a
runDelay (now x) now = x
runDelay (later y) (later p) = runDelay (y .force) p

plus possibly a proof that the result of runDelay is indeed equal to x.

@jespercockx
Copy link
Member Author

@flupe this is ready now, could you do a quick review?

@flupe
Copy link
Contributor

flupe commented Jan 17, 2024

lgtm

@flupe flupe merged commit 984821a into agda:master Jan 17, 2024
7 checks passed
@jespercockx jespercockx added this to the 1.3 milestone Feb 23, 2024
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