Created
March 31, 2026 18:53
-
-
Save Solonarv/13530b216370ea8fd780aea569c0d5eb to your computer and use it in GitHub Desktop.
generating `Typeable` types at runtime :3
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
| module Cursed where | |
| import Data.Typeable | |
| data Some where Some :: Typeable x => x -> Some | |
| data Null = Null | |
| data O x = O x | |
| data I x = I x | |
| bit0, bit1 :: Some -> Some | |
| bit0 (Some x) = Some (O x) | |
| bit1 (Some x) = Some (I x) | |
| w2Some :: Word -> Some | |
| w2Some 0 = Some Null | |
| w2Some n = let (n', r) = n `divMod` 2 | |
| in (if r==0 then bit0 else bit1) (w2Some n') | |
| typeOfSome (Some x) = typeOf x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment