Last active
August 29, 2015 13:56
-
-
Save msfroh/9320420 to your computer and use it in GitHub Desktop.
This file contains 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
public class Grammar { | |
static interface Subject { | |
default Subject and(Subject other) { return new Subject() {}; } | |
// Define both talkTo and talksTo to ensure "sentences" below | |
// have subject-verb agreement. | |
default void talksTo(Obj obj) {} | |
default void talkTo(Obj obj) {} | |
} | |
static interface Obj { | |
default Obj and(Obj other) { return new Obj() {}; } | |
} | |
static class Name implements Subject, Obj {} | |
private static final Subject I = new Subject() {}; | |
private static final Obj me = new Obj() {}; | |
} |
This file contains 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
// This works -- Jim.and(I) is a Subject | |
Jim.and(I).talkTo(Jane); | |
// This works, Jane.and(me) is an Obj | |
Jim.talksTo(Jane.and(me)); | |
// Doesn't compile -- Jim.and(me) is an Obj. Doesn't have talkTo. | |
// Jim.and(me).talkTo(Jane); | |
// Doesn't compile -- Jane.and(I) is a Subject. Invalid argument. | |
// Jim.talksTo(Jane.and(I)); |
This file contains 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
public class Grammar { | |
static interface Subject { | |
// ... previous definition of and ... | |
default void veGot(Obj obj){}; | |
default void feelTheMagicBetween(Obj obj) {} | |
} | |
// you isn't really a name, but the same pronoun works as subject and object | |
private static final Name you = new Name(); | |
// Same thing with hungry eyes | |
private static final Name hungryEyes = new Name(); | |
static { | |
I.veGot(hungryEyes); | |
// The following doesn't compile. Sorry Eric Carmen. | |
// I.feelTheMagicBetween(you.and(I)); | |
// The following compiles, but doesn't even kind of rhyme. | |
I.feelTheMagicBetween(you.and(me)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment