Last active
November 19, 2019 21:08
-
-
Save okram/93859108c661745819a93e9755ca2027 to your computer and use it in GitHub Desktop.
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
// there is an interesting algebra we need to define | |
mmadt> int{3} <= [start,1,2,3] // int{3} is a 'reference' to the stream 1,2,3 | |
==>1 | |
==>2 | |
==>3 | |
mmadt> int{3} <= [start,1,2,3] => int // the int{3} reference is => (mapped-to) the int type. | |
==>1 // the RHS int serves as a filter instruction (compiles to [is,[a,int]]) | |
==>2 | |
==>3 | |
mmadt> int{3} <= [start,1,2,3] => str // the streaming ints are not strs so they are filtered out. | |
mmadt> | |
/* | |
Whats interesting is that each obj has a "maps from" and a "maps to" instruction sequence. | |
int{3} <= [start,1,2,3] => int | |
int{3} "maps from" [start,1,2,3] | |
int{3} "maps to" int | |
How does <= and => mutate when chained? | |
int{3} <= [start,1,2,3] => int <= [plus,10] => [mult,5] | |
*/ | |
// maps-to | |
mmadt> int{3} <= [start,1,2,3] => (int <= [plus,10] => [mult,5]) // the second int is "dependently generated" via [plus,10] | |
==>int{0,3} <= [start,1,2,3][plus,10][is,[a,int]][mult,5] // hence the compilation to int{0,3} | |
mmadt> int{0,3} <= [start,1,2,3][plus,10][is,[a,int]][mult,5] | |
==>55 | |
==>60 | |
==>65 | |
// maps-from | |
mmadt> int <= (int{3} <= [start,1,2,3][plus,10] => [mult,5]) // note that [mult,5] is placed after the int <= generator. this could lead to a type error as it is not definitial/generating of int. Is this bad? | |
==>55 | |
==>60 | |
==>65 | |
/////////// | |
// here is the algebra I have thus far. It tells you how <= is related to =>. | |
public default <O extends Obj> O mapFrom(final Obj obj) { | |
return obj instanceof Inst ? this.appendFrom((Inst) obj) : this.q(this.q().mult(obj.q())).accessFrom(obj.accessFrom()).appendFrom(obj.accessTo()).appendFrom(this.accessFrom()).appendFrom(IsInst.isA(this)); | |
} | |
public default <O extends Obj> O mapTo(final Obj obj) { | |
return obj instanceof Inst ? this.appendTo((Inst) obj) : obj.mapFrom(this); | |
// mapTo is defined in terms of mapFrom (symmetric) | |
// obj.q(obj.q().mult(this.q())).accessFrom(this.accessFrom()).appendFrom(this.accessTo()).appendFrom(obj.accessFrom()).appendFrom(IsInst.isA(obj)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment