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

Type checker does not terminate when comparing codata types. #3209

Open
yellowsquid opened this issue Jan 31, 2024 · 2 comments
Open

Type checker does not terminate when comparing codata types. #3209

yellowsquid opened this issue Jan 31, 2024 · 2 comments

Comments

@yellowsquid
Copy link

yellowsquid commented Jan 31, 2024

Uncommenting oops or uhOh and then type checking causes Idris to loop indefinitely.

index : Nat -> Stream a -> a
index 0     (x :: xs) = x
index (S k) (x :: xs) = index k xs

iterate : (a -> a) -> a -> Stream a
iterate f x = x :: iterate f (f x)

Pred : Type
Pred = Type

fix : (Pred -> Pred) -> Pred
fix f = (n ** index n (iterate f Void))

oops : {n : Nat} -> index n (iterate f Void) -> fix f
-- oops {n} prf = (n ** prf)

uhOh : {n : Nat} -> index n (iterate f ()) -> index n (iterate f Void)
-- uhOh prf = prf

Environment

Idris commit: d34cf62

Steps to Reproduce

  1. Type check the snippet.
  2. Uncomment the definition of oops.
  3. Type check the snippet again.
  4. Uncomment the definition of uhOh.
  5. Type check the snippet one last time.

Expected Behavior

Idris should accept the program as correct after uncommenting oops. It should provide a type error when uncommenting uhOh.

Observed Behavior

Idris will enter a seemingly infinite loop when uncommenting either definition.

Further Details

Idris works correctly for oops if you inline either Pred or fix.

The problem remains for oops if you:

  • import Data.Stream to provide iterate and index
  • make Pred more complex (in my original use case, Pred = Nat -> Type)
  • use a custom record instead of dependent pairs

No changes I have tried have caused uhOh to terminate.

@buzden
Copy link
Contributor

buzden commented Jan 31, 2024

Is this #964?

@yellowsquid
Copy link
Author

yellowsquid commented Jan 31, 2024

Yes, but the bug when things don't unify seems to be a new observation. Feel free to close this as a duplicate and I'll update the original issue.

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

No branches or pull requests

2 participants