Last active
January 20, 2026 11:01
-
-
Save johannes-riecken/f3d60c62f3484a5b524e97f0ea473d70 to your computer and use it in GitHub Desktop.
Totality checking failure for mutually recursive type class instances
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
| %default total | |
| data Tree a = Leaf a | Fork (List (Tree a)) | |
| interface Encode a where | |
| encode : a -> List Bool | |
| mutual | |
| Encode a => Encode (List a) where | |
| encode [] = [False] | |
| encode (x :: xs) = True :: encode x ++ encode xs | |
| Encode a => Encode (Tree a) where | |
| encode (Leaf x) = [False] | |
| encode (Fork []) = [True, False] | |
| encode (Fork (x :: xs)) = True :: True :: encode x ++ encode xs |
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
| %default total | |
| data Tree a = Leaf a | Fork (List (Tree a)) | |
| interface Encode a where | |
| encode : a -> List Bool | |
| mutual | |
| encodeList : Encode a => List (Tree a) -> List Bool | |
| encodeList [] = [False] | |
| encodeList (x :: xs) = True :: encodeTree x ++ encodeList xs | |
| encodeTree : Encode a => Tree a -> List Bool | |
| encodeTree (Leaf x) = [False] | |
| encodeTree (Fork []) = [True, False] | |
| encodeTree (Fork (x :: xs)) = True :: True :: encodeTree x ++ encodeList xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment