Last active
June 17, 2020 00:44
-
-
Save puffnfresh/652a75b053bbf06467a215e8bd7dd57b to your computer and use it in GitHub Desktop.
Encoding Booleans in Featherweight Generic Go
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
package main; | |
type Any(type) interface { }; | |
type Name(type a Any()) interface { | |
value(type)() a | |
}; | |
type Value(type a Any()) struct { | |
value a | |
}; | |
func (this Value(type a Any())) value(type)() a { | |
return this.value | |
}; | |
type Boolean(type) interface { | |
iff(type a Any())(t Name(a), f Name(a)) a | |
}; | |
type True(type) struct { }; | |
func (this True(type)) iff(type a Any())(t Name(a), f Name(a)) a { return t.value()() }; | |
type False(type) struct { }; | |
func (this False(type)) iff(type a Any())(t Name(a), f Name(a)) a { return f.value()() }; | |
type Example(type) struct { }; | |
func (this Example(type)) not(type)(b Boolean(type)) Boolean(type) { | |
return b.iff(Boolean())(Value(Boolean()){False(){}}, Value(Boolean()){True(){}}) | |
}; | |
func main() { | |
_ = Example(){}.not()(True(){}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment