| | 861 | (************************************************************ |
|---|
| | 862 | * Meta-generators: BIG GENERATOR |
|---|
| | 863 | ************************************************************) |
|---|
| | 864 | |
|---|
| | 865 | (** The problem: Your code is sprinkled with the same generator code, |
|---|
| | 866 | over and over again. Maybe it looks something like this: |
|---|
| | 867 | % for (i,v) <- a.indexValuePairs(), v =/= 0, j <- 0:i do (code using i and j) % |
|---|
| | 868 | You goal: abstract this into a single generator. You can do this as follows: |
|---|
| | 869 | % usefulGen = BIG GENERATOR[(i,v) <- a.indexValuePairs(), v =/= 0, j <- 0:i] (i,j) % |
|---|
| | 870 | Not much savings there, but the important part is that you can just |
|---|
| | 871 | cut and paste the generators from the original code. And all occurrences |
|---|
| | 872 | can be cleaned up: |
|---|
| | 873 | % for (i,j) <- usefulGen do (code using i and j) % |
|---|
| | 874 | This is possible using %map%, %filter%, and %nest%, but you end up |
|---|
| | 875 | effectively desugaring the code by hand. Using BIG GENERATOR is much easier. |
|---|
| | 876 | **) |
|---|
| | 877 | |
|---|
| | 878 | (** TODO |
|---|
| | 879 | |
|---|
| | 880 | The big problem here is that the new desugaring story actually gets in |
|---|
| | 881 | the way. We can't simply package up a function passed in, because |
|---|
| | 882 | that's being done by the __bigOperator functionality directly. |
|---|
| | 883 | |
|---|
| | 884 | How do we deal with reduction properties? It's all very sticky. And |
|---|
| | 885 | we're already running into difficulties with co- and contra-variance |
|---|
| | 886 | of the type parameters floating around that force us to use Any in |
|---|
| | 887 | awkward places. |
|---|
| | 888 | |
|---|
| | 889 | In particular, we don't want to generate the data when creating the |
|---|
| | 890 | generator, as that misses the whole point. We want to defer the |
|---|
| | 891 | object traversals until the moment the resulting generator is used. |
|---|
| | 892 | **) |
|---|