Skip to content

Instantly share code, notes, and snippets.

@puffnfresh
Last active June 17, 2020 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save puffnfresh/652a75b053bbf06467a215e8bd7dd57b to your computer and use it in GitHub Desktop.
Save puffnfresh/652a75b053bbf06467a215e8bd7dd57b to your computer and use it in GitHub Desktop.
Encoding Booleans in Featherweight Generic Go
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