Last active
September 23, 2020 07:51
-
-
Save Russoul/cbd00a08c39b926b6fb192514797023d to your computer and use it in GitHub Desktop.
(Rough) Translation of interfaces to data and function definitions
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
| -- interface A x where | |
| -- constructor MkA | |
| -- methodA : x | |
| -- interface A x => B x where | |
| -- constructor MkB | |
| -- methodB : x | |
| -- A Bool where | |
| -- methodA = True | |
| -- A Bool where | |
| -- methodB = False | |
| -- TRANSLATION START -- | |
| data A : (x : Type) -> Type where | |
| [noHints] | |
| MkA : {-methodA instance-} (_ : x) -> A x | |
| data B : (x : Type) -> Type where | |
| [noHints] | |
| MkB : {-constraint instance-} A x -> {-methodB instance-} (_ : x) -> B x | |
| methodA : {auto ax : A x} -> x | |
| methodA @{MkA method} = method | |
| methodB : {auto bx : B x} -> x | |
| methodB @{MkB _ method} = method | |
| %hint | |
| aBoolInstance {-machine name-} : A Bool | |
| aBoolInstance = MkA True | |
| %hint | |
| bBoolInstance {-machine name-} : {auto ainst : A Bool} -> B Bool | |
| bBoolInstance = MkB ainst False | |
| -- TRANSLATION END -- | |
| -- (x : Foo) => Bar ≡ {auto x : Foo} -> Bar | |
| getA : B x => A x | |
| getA @{MkB ax methodB} = ax | |
| test : Bool | |
| test = methodA @{%search} == not (methodB @{%search}) | |
| testCompileTime : Main.test = True | |
| testCompileTime = Refl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment