Changeset 1825

Show
Ignore:
Timestamp:
06/06/08 17:43:51 (6 months ago)
Author:
jmaessen
Message:

New comprehension/reduction desugaring (part I). Big operators now
take no arguments and return a BigOperator? object; this and the old
desugaring are taken as arguments by the bigOperator function to
produce the result of the comprehension or reduction. Next step is
double reductions.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Library/FortressLibrary.fsi

    r1810 r1825  
    500500__generate[\E,R\](g:Generator[\E\], r: Reduction[\R\], b:E->R): R 
    501501 
     502__filter[\E\](g:Generator[\E\], p:E->Condition[\()\]): Generator[\E\] 
     503__bigOperator[\I,O,R,L\](o:BigOperator[\I,O,R,L\],desugaredClauses:(Reduction[\L\],I->L)->L): O 
     504 
    502505(* Not currently used for desugaring, but will be used in future. 
    503506__nest[\E1,E2\](g:Generator[\E1\], f:E1->Generator[\E2\]):Generator[\E2\] 
     
    14451448end 
    14461449 
    1447 trait BigOperator[\I,R,L\] 
     1450trait BigOperator[\I,O,R,L\] 
    14481451    abstract getter reduction(): ActualReduction[\R,L\] 
    14491452    abstract getter body(): I->R 
    1450 end 
    1451  
    1452 object BigReduction[\R,L\](r:ActualReduction[\R,L\]) extends BigOperator[\R,R,L\] 
     1453    abstract getter unwrap(): R->O 
     1454end 
     1455 
     1456object BigReduction[\R,L\](r:ActualReduction[\R,L\]) extends BigOperator[\R,R,R,L\] 
    14531457    getter reduction(): ActualReduction[\R,L\] 
    14541458    getter body(): R->R 
    1455 end 
    1456  
    1457 object Comprehension[\I,R,L\](r: ActualReduction[\R,L\], singleton:I->R) 
    1458         extends BigOperator[\I,R,L\] 
     1459    getter unwrap(): R->R 
     1460end 
     1461 
     1462object Comprehension[\I,O,R,L\](u: R->O, r: ActualReduction[\R,L\], singleton:I->R) 
     1463        extends BigOperator[\I,O,R,L\] 
    14591464    getter reduction(): ActualReduction[\R,L\] 
    14601465    getter body(): I->R 
     1466    getter unwrap(): R->O 
    14611467end 
    14621468 
  • trunk/Library/FortressLibrary.fss

    r1810 r1825  
    620620        SimpleNestedGenerator[\E,G\](self,f) 
    621621 
     622    (** Filtering data from a generator.  Only elements that satisfy 
     623        the predicate p are retained.  Natural order and cross product 
     624        properties are otherwise preserved. **) 
     625    filter(f: E -> Condition[\()\]): Generator[\E\] = 
     626        SimpleFilterGenerator[\E\](self,f) 
     627 
    622628    (** Cross product of two generators.  This is specifically 
    623629        designed to be overloaded, such that pairs of independent 
     
    699705 
    700706(** Unlike the user-visible dotted map method, this method is used for 
    701     the internals of comprehension desugaring.  As a result we know 
    702     that its result will immediately be consumed, and we should *not* 
    703     create an intermediate collection if we're passed a 
    704     collection. **) 
     707    the internals of comprehension desugaring [except that at present 
     708    it is not actually in use, but we're planning to use it].  As a 
     709    result we know that its result will immediately be consumed, and 
     710    we should *not* create an intermediate collection if we're passed 
     711    a collection. **) 
    705712__map[\E,R\](g:Generator[\E\], f:E->R): Generator[\R\] = 
    706713    typecase g of 
     714        SomeMappedGenerator[\E\] => g.map[\R\](f) 
    707715        SequentialGenerator[\E\] => SimpleMappedSeqGenerator[\E,R\](g,f) 
    708716        else => SimpleMappedGenerator[\E,R\](g,f) 
    709717    end 
     718 
     719(** Unlike the user-visible dotted filter method, but like the __map 
     720    method, this method is intended for use in the internals of 
     721    comprehension desugaring.  Again its result will immediately be 
     722    consumed, and we do not create an intermediate collection but 
     723    perform the filtering lazily on demand. **) 
     724__filter[\E\](g:Generator[\E\], p:E->Condition[\()\]): Generator[\E\] = 
     725    typecase g of 
     726        FilterGenerator[\E\] => g.filter(p) 
     727        SequentialGenerator[\E\] => SimpleSeqFilterGenerator[\E\](g,p) 
     728        else => SimpleFilterGenerator[\E\](g,p) 
     729    end 
     730 
     731(** Application of a BIG operator, the topmost level of comprehension desugaring. **) 
     732__bigOperator[\I,O,R,L\](o:BigOperator[\I,O,R,L\],desugaredClauses:(Reduction[\L\],I->L)->L): O = do 
     733    r = o.reduction() 
     734    body(i): L = r.lift((o.body())(i)) 
     735    (o.unwrap())(r.unlift(desugaredClauses(r,body))) 
     736  end 
    710737 
    711738trait SequentialGenerator[\E\] extends { Generator[\E\] } 
     
    770797    opr IN(x:E, self):Boolean = cond[\Boolean\](fn (e:E):Boolean => x=e, fn () => false) 
    771798end 
     799 
     800(** Conjunction and disjunction of condition functions **) 
     801opr ANDCOND[\I\](p1:I->Condition[\()\], p2:I->Condition[\()\]): I->Condition[\()\] = 
     802    fn (i:I):Boolean => p1(i).holds() AND: p2(i).holds() 
     803 
     804(** Conjunction and disjunction of condition functions **) 
     805opr ORCOND[\I\](p1:I->Condition[\()\], p2:I->Condition[\()\]): I->Condition[\()\] = 
     806    fn (i:I):Boolean => p1(i).holds() OR: p2(i).holds() 
    772807 
    773808(** Operations which use generation internally.  Should be functional 
     
    21592194    empty(): L 
    21602195    join(a: L, b: L): L 
    2161     lift(r:R): L 
     2196    lift(r: Any): L 
    21622197    unlift(l:L): R 
    21632198    (** If this reduction left-distributes over r, return a pair of 
    21642199        reductions with the same lift and unlift **) 
    2165     leftDistribute(r: Reduction[\R\]): Maybe[\(Reduction[\R\],Reduction[\R\])\] = 
     2200    leftDistribute(r: Reduction[\R\]): SomeReductionPair[\R\] = 
    21662201        distribute(r) 
    21672202    (** If this reduction right-distributes over r, return a pair of 
    21682203        reductions with the same lift and unlift **) 
    2169     rightDistribute(r: Reduction[\R\]): Maybe[\(Reduction[\R\],Reduction[\R\])\] = 
     2204    rightDistribute(r: Reduction[\R\]): SomeReductionPair[\R\] = 
    21702205        distribute(r) 
    21712206    (** If this reduction distributes over r, return a pair of 
    21722207        reductions with the same lift and unlift **) 
    2173     distribute(r: Reduction[\R\]): Maybe[\(Reduction[\R\],Reduction[\R\])\] = 
    2174         Nothing[\(Reduction[\R\],Reduction[\R\])\] 
     2208    distribute[\K\](r: ActualReduction[\R,K\]): SomeReductionPair[\R\] = 
     2209        NoReductionPair[\R\] 
    21752210end 
    21762211 
     
    21972232 
    21982233(** The usual lifting to Maybe for identity-less operators **) 
    2199 trait AssociativeReduction[\R\] extends ActualReduction[\R,Maybe[\R\]\] 
     2234trait AssociativeReduction[\R\] extends ActualReduction[\R,AnyMaybe\] 
    22002235    empty(): Nothing[\R\] = Nothing[\R\] 
    2201     join(a: Maybe[\R\], b: Maybe[\R\]): Maybe[\R\]
     2236    join(a: AnyMaybe, b: AnyMaybe): AnyMaybe
    22022237        if av <- a then 
    22032238            if bv <- b then 
    2204                 Just[\R\](simpleJoin(av,bv)) 
     2239                Just(simpleJoin(av,bv)) 
    22052240            else 
    22062241                a 
     
    22092244            b 
    22102245        end 
    2211     simpleJoin(a:R, b:R): R 
    2212     lift(r:R): Maybe[\R\] = Maybe[\R\](r) 
    2213     unlift(r:Maybe[\R\]): R = r.get() 
     2246    simpleJoin(a:Any, b:Any): Any 
     2247    lift(r:Any): AnyMaybe = Just(r) 
     2248    unlift(r:AnyMaybe): R = r.get() 
    22142249end 
    22152250 
     
    22182253(** Monoids don't require a special lift and unlift operation. **) 
    22192254trait MonoidReduction[\R\] extends ActualReduction[\R,R\] 
    2220     lift(r:R): R = r 
     2255    lift(r:Any): R = r 
    22212256    unlift(r:R): R = r 
    22222257end 
     
    22302265end 
    22312266 
    2232 trait BigOperator[\I,R,L\] 
     2267trait BigOperator[\I,O,R,L\] 
    22332268    getter reduction(): ActualReduction[\R,L\] 
    22342269    getter body(): I->R 
    2235 end 
    2236  
    2237 object BigReduction[\R,L\](r:ActualReduction[\R,L\]) extends BigOperator[\R,R,L\] 
     2270    getter unwrap(): R->O 
     2271end 
     2272 
     2273object BigReduction[\R,L\](r:ActualReduction[\R,L\]) extends BigOperator[\R,R,R,L\] 
    22382274    getter reduction(): ActualReduction[\R,L\] = r 
    2239     getter body(): R->R = identity[\R\] 
    2240 end 
    2241  
    2242 object Comprehension[\I,R,L\](r: ActualReduction[\R,L\], singleton:I->R) 
    2243         extends BigOperator[\I,R,L\] 
     2275    getter body(): R->R = fn x => x 
     2276    getter unwrap(): R->R = fn x => x 
     2277end 
     2278 
     2279object Comprehension[\I,O,R,L\](u: R->O, r: ActualReduction[\R,L\], singleton:I->R) 
     2280        extends BigOperator[\I,O,R,L\] 
    22442281    getter reduction(): ActualReduction[\R,L\] = r 
    22452282    getter body(): I->R = singleton 
     2283    getter unwrap(): R->O = u 
    22462284end 
    22472285 
     
    22632301end 
    22642302 
    2265 opr SUM[\T\](g:(Reduction[\Number\],T->Number)->Number): Number
    2266     g(SumReduction,cast[\Number\]) 
     2303opr SUM[\T extends Number\](): Comprehension[\T,Number,Number,Number\]
     2304    Comprehension[\T,Number,Number,Number\](fn x => x, SumReduction, cast[\Number\]) 
    22672305 
    22682306object ProdReduction extends CommutativeMonoidReduction[\Number\] 
     
    22722310end 
    22732311 
    2274 opr PROD[\T\](g:(Reduction[\Number\],T->Number)->Number): Number
    2275     g(ProdReduction,cast[\Number\]) 
     2312opr PROD[\T extends Number\](): Comprehension[\T,Number,Number,Number\]
     2313    Comprehension[\T,Number,Number,Number\](fn x => x, ProdReduction, cast[\Number\]) 
    22762314 
    22772315object MinReduction[\T extends StandardMin[\T\]\] extends CommutativeReduction[\T\] 
    22782316    getter toString() = "MinReduction" 
    2279     simpleJoin(a:T, b:T): T = a MIN b 
    2280 end 
    2281  
    2282 opr BIG MIN[\T extends StandardMin[\T\]\] 
    2283            (g:(MinReduction[\T\],T->AnyMaybe)->AnyMaybe): T = 
    2284         g(MinReduction[\T\],just).get() 
     2317    simpleJoin(a, b) = a MIN b 
     2318end 
     2319 
     2320opr BIG MIN[\T extends StandardMin[\T\]\](): BigReduction[\T,AnyMaybe\] = 
     2321    BigReduction[\T,AnyMaybe\](MinReduction[\T\]) 
    22852322 
    22862323object MaxReduction[\T extends StandardMax[\T\]\] extends CommutativeReduction[\T\] 
    22872324    getter toString() = "MaxReduction" 
    2288     simpleJoin(a:T, b:T): T = a MAX b 
    2289 end 
    2290  
    2291 opr BIG MAX[\T extends StandardMax[\T\]\] 
    2292            (g:(MaxReduction[\T\],T->AnyMaybe)->AnyMaybe): T = 
    2293         g(MaxReduction[\T\],just).get() 
    2294  
    2295 opr BIG MINNUM(g:(Reduction[\RR64\],RR64->RR64)->RR64): RR64 = 
    2296     g(MapReduceReduction[\RR64\](fn (a:RR64,b:RR64):RR64 => a MINNUM b, 0.0/0.0), 
    2297       identity[\RR64\]) 
    2298  
    2299 opr BIG MAXNUM(g:(Reduction[\RR64\],RR64->RR64)->RR64): RR64 = 
    2300     g(MapReduceReduction[\RR64\](fn (a:RR64,b:RR64):RR64 => a MINNUM b, 0.0/0.0), 
    2301       identity[\RR64\]) 
     2325    simpleJoin(a, b) = a MAX b 
     2326end 
     2327 
     2328opr BIG MAX[\T extends StandardMax[\T\]\](): BigReduction[\T,AnyMaybe\] = 
     2329    BigReduction[\T,AnyMaybe\](MaxReduction[\T\]) 
     2330 
     2331opr BIG MINNUM(): BigReduction[\RR64,RR64\] = 
     2332    BigReduction[\RR64,RR64\]( 
     2333        MapReduceReduction[\RR64\](fn (a:RR64,b:RR64):RR64 => a MINNUM b, 0.0/0.0)) 
     2334 
     2335opr BIG MAXNUM(): BigReduction[\RR64,RR64\] = 
     2336    BigReduction[\RR64,RR64\]( 
     2337        MapReduceReduction[\RR64\](fn (a:RR64,b:RR64):RR64 => a MAXNUM b, 0.0/0.0)) 
    23022338 
    23032339(** AndReduction and OrReduction take advantage of natural zeroes for early exit. **) 
     
    23112347end 
    23122348 
    2313 opr BIG AND[\T\](g:(Reduction[\Boolean\],T->Boolean)->Boolean):Boolean = 
    2314     label MustBe 
    2315         f(x): Boolean = 
    2316             typecase x of 
    2317                 Boolean => if x then true else exit MustBe with false end 
    2318                 else => fail("BIG AND of non-boolean") 
    2319             end 
    2320         g(AndReduction, f) 
    2321     end MustBe 
     2349opr BIG AND[\T\](): BigReduction[\Boolean,Boolean\] = 
     2350    BigReduction[\Boolean,Boolean\](AndReduction) 
    23222351 
    23232352object OrReduction 
     
    23302359end 
    23312360 
    2332 opr BIG OR[\T\](g:(Reduction[\Boolean\],T->Boolean)->Boolean):Boolean = 
    2333     label MustBe 
    2334         f(x): Boolean = 
    2335             typecase x of 
    2336                 Boolean => if x then exit MustBe with true else false end 
    2337                 else => fail("BIG OR of non-boolean") 
    2338             end 
    2339         g(OrReduction, f) 
    2340     end MustBe 
     2361opr BIG OR[\T\]():BigReduction[\Boolean, Boolean\] = 
     2362    BigReduction[\Boolean,Boolean\](OrReduction) 
    23412363 
    23422364(** A reduction performing String concatenation **) 
     
    23572379object NewlineReduction extends AssociativeReduction[\String\] 
    23582380    getter toString() = "StringReduction" 
    2359     simpleJoin(a:String, b:String): String = a // b 
     2381    simpleJoin(a, b) = a // b 
    23602382end 
    23612383 
    23622384(** This operator performs string concatenation, first converting 
    23632385    its inputs (of type Any) to String if necessary. **) 
    2364 opr BIG ||(g:(Reduction[\String\],Any->String)->String): String = 
    2365     g(StringReduction, fn (x:Any)=> "" x) 
     2386opr BIG ||(): String = 
     2387    Comprehension[\Any,String,String,String\]( 
     2388        identity[\String\],StringReduction,fn (x:Any)=> "" x) 
    23662389 
    23672390(** This operator performs string concatenation, first converting 
    23682391    its inputs (of type Any) to String if necessary, and separating 
    23692392    non-empty components by a space. **) 
    2370 opr BIG |||(g:(Reduction[\String\],Any->String)->String): String = 
    2371     g(SpaceReduction, fn (x:Any)=> "" x) 
     2393opr BIG |||(): Comprehension[\Any,String,String,String\] = 
     2394    Comprehension[\Any,String,String,String\]( 
     2395        identity[\String\],SpaceReduction,fn (x:Any)=> "" x) 
    23722396 
    23732397(** This operator performs string concatenation with newline 
    23742398    separation, first converting its inputs (of type Any) to String if 
    23752399    necessary. **) 
    2376 opr BIG //(g:(Reduction[\Maybe[\String\]\],Any->Maybe[\String\])->Maybe[\String\]): String = 
    2377     g(NewlineReduction, fn (x:Any)=> Just[\String\]("" x)).get() 
     2400opr BIG //(): Comprehension[\Any,String,AnyMaybe,AnyMaybe\] = 
     2401    Comprehension[\Any,String,AnyMaybe,AnyMaybe\]( 
     2402        fn x => x,NewlineReduction,fn (x:Any)=> "" x) 
    23782403 
    23792404(** A %MapReduceReduction% takes an associative binary function %j% on 
     
    24032428    g(MIOprReduction[\T,OP\](z), fn (x) => x) 
    24042429*) 
    2405 embiggen[\T\](j:(Any,Any)->T, z:Any, g:(Reduction[\T\],T->Any) -> Any) : T
    2406     g(MIMapReduceReduction[\T\](j,z), fn (x) => x) 
     2430embiggen[\T\](j:(Any,Any)->T, z:T) : Comprehension[\T,T,Any,Any\]
     2431    Comprehension[\T,T,Any,Any\](fn (x) => x, MIMapReduceReduction[\T\](j,z), fn (x) => x) 
    24072432 
    24082433(** Helpers for maps and cross products of generators.  These can be 
     
    24102435    outwards if we think that'd be useful), but let's get this much 
    24112436    working first. *) 
    2412  
    2413 trait MappedGenerator[\E,F\] extends Generator[\F\] 
     2437trait SomeMappedGenerator[\F\] extends Generator[\F\] end 
     2438 
     2439trait MappedGenerator[\E,F\] extends SomeMappedGenerator[\F\] 
    24142440    getter g(): Generator[\E\] 
    24152441    getter f(): E -> F 
     
    24562482    getter toString() = "seq(" g0 ".map(f))" 
    24572483    seq(self): SimpleMappedSeqGenerator[\E,F\] = self 
     2484end 
     2485 
     2486trait FilterGenerator[\E\] extends Generator[\E\] 
     2487    getter g(): Generator[\E\] 
     2488    getter p(): E -> Condition[\()\] 
     2489    getter toString(): String = g() ".filter(p)" 
     2490    generate[\R\](r:Reduction[\R\], m: E->R): R = 
     2491        g().generate[\R\](r, fn(e:E):R => if (p())(e).holds() then m(e) else r.empty() end) 
     2492    reduce(r: Reduction[\E\]): E = 
     2493        g().generate[\E\](r, fn(e:E):E => if (p())(e).holds() then e else r.empty() end) 
     2494    filter(p': E -> Condition[\E\]): SimpleFilterGenerator[\E\] = 
     2495        SimpleFilterGenerator[\E\](g(), p() ANDCOND p') 
     2496    seq(self) = SimpleSeqFilterGenerator[\E\](g(),p()) 
     2497end 
     2498 
     2499object SimpleFilterGenerator[\E\](g0:Generator[\E\], p0: E->Condition[\()\]) 
     2500        extends FilterGenerator[\E\] 
     2501    getter g(): Generator[\E\]       = g0 
     2502    getter p(): E -> Condition[\()\]  = p0 
     2503end 
     2504 
     2505object SimpleSeqFilterGenerator[\E\](g0: SequentialGenerator[\E\], p0: E->Condition[\()\]) 
     2506        extends { FilterGenerator[\E\], SequentialGenerator[\E\] } 
     2507    getter g(): Generator[\E\]       = g0 
     2508    getter p(): E -> Condition[\()\]  = p0 
     2509    getter toString() = "seq(" g0 ".filter(p))" 
     2510    seq(self): SimpleSeqFilterGenerator[\E\] = self 
    24582511end 
    24592512 
  • trunk/Library/List.fsi

    r1786 r1825  
    115115opr <|[\E\] xs: E... |>: List[\E\] 
    116116(** List comprehensions: *) 
    117 opr BIG <|[\T\] g: ( Reduction[\SomeList\], T->SomeList) -> SomeList |>: List[\T\] 
     117opr BIG <|[\T\]|>:Comprehension[\T,List[\T\],List[\T\],List[\T\]\] 
    118118 
    119119(** Convert generator into list (simpler type than comprehension above): *) 
     
    139139(** Utility for cooking up covariant comprehensions of other 
    140140    (non-covariant) types. **) 
    141 covariantComprehension[\T\]( g: (Reduction[\SomeList\], T->SomeList) -> SomeList): List[\T\] 
     141covariantComprehension[\T,R\](unwrap:List[\T\]->R): Comprehension[\T,R,List[\T\],List[\T\]\] 
    142142 
    143143end 
  • trunk/Library/List.fss

    r1786 r1825  
    176176(** Vararg factory for lists; provides aggregate list constants **) 
    177177opr <|[\E\] xs: E... |>: List[\E\] = list(xs) 
    178 opr BIG <|[\T\] g: ( Reduction[\SomeList\], T->SomeList) -> SomeList |>: List[\T\] = 
    179     covariantComprehension[\T\](g) 
    180  
    181 covariantComprehension[\T\]( g: (Reduction[\SomeList\], T->SomeList) -> SomeList): List[\T\] = 
    182     g(CVConcat[\T\],cvSingleton).append(emptyList[\T\]()) 
     178opr BIG <|[\T\]|>: Comprehension[\T,List[\T\],SomeList,SomeList\] = 
     179    covariantComprehension[\T,List[\T\]\](fn (x) => x) 
     180 
     181covariantComprehension[\T,R\](unwrap:SomeList->R): Comprehension[\T,R,SomeList,SomeList\] = 
     182    Comprehension[\T,R,SomeList,SomeList\]( 
     183        fn xs => unwrap(xs.append(emptyList[\T\]())), CVConcat[\T\], cvSingleton) 
    183184 
    184185(** Convert generator into list; can be used to desugar list 
  • trunk/Library/Map.fss

    r1786 r1825  
    158158    mapping[\Key,Val\](xs) 
    159159 
    160 opr BIG {|->[\Key,Val\] g: ( Reduction[\SomeList\], (Key,Val) -> SomeList) -> 
    161                            SomeList } : Map[\Key,Val\] = 
    162     mapping(covariantComprehension[\(Key,Val)\](g)) 
    163  
    164 opr BIG UNION[\Key,Val\](g: ( Reduction[\Map[\Key,Val\]\], 
    165                               Map[\Key,Val\] -> Map[\Key,Val\]) -> 
    166                             Map[\Key,Val\] ) : Map[\Key,Val\] = 
    167     embiggen[\ Map[\Key,Val\] \](fn (a,b) => a UNION b, EmptyMap[\Key,Val\], g) 
    168  
    169 opr BIG UPLUS[\Key,Val\](g: ( Reduction[\Map[\Key,Val\]\], 
    170                               Map[\Key,Val\] -> Map[\Key,Val\]) -> 
    171                             Map[\Key,Val\] ) : Map[\Key,Val\] = 
    172     embiggen[\ Map[\Key,Val\] \](fn (a,b) => a UPLUS b, EmptyMap[\Key,Val\], g) 
     160opr BIG {|->[\Key,Val\] } : Comprehension[\(Key,Val),Map[\Key,Val\],SomeList,SomeList\] = 
     161    covariantComprehension[\(Key,Val),Map[\Key,Val\]\](fn g => mapping(g)) 
     162 
     163opr BIG UNION[\Key,Val\]() : Comprehension[\Map[\Key,Val\],Map[\Key,Val\],Any,Any\] = 
     164    embiggen[\ Map[\Key,Val\] \](fn (a,b) => a UNION b, EmptyMap[\Key,Val\]) 
     165 
     166opr BIG UPLUS[\Key,Val\]() : Comprehension[\Map[\Key,Val\],Map[\Key,Val\],Any,Any\] = 
     167    embiggen[\ Map[\Key,Val\] \](fn (a,b) => a UPLUS b, EmptyMap[\Key,Val\]) 
    173168 
    174169object SeqMapGenerator[\Key,Val\](o:Map[\Key,Val\]) 
  • trunk/Library/PureList.fss

    r1786 r1825  
    8080(** Vararg factory for lists; provides aggregate list constants **) 
    8181opr <|[\E\] xs: E... |>: List[\E\] = list(xs) 
    82 opr BIG <|[\T\] g: ( Reduction[\SomeList\], T->SomeList) -> SomeList|>: List[\T\] = 
    83     list(covariantComprehension[\T\](g)) 
     82opr BIG <|[\T\]|>: Comprehension[\T,List[\T\],SomeList,SomeList\] = 
     83    covariantComprehension[\T,List[\T\]\](fn x => list(x)) 
    8484 
    8585(** Convert generator into list; can be used to desugar list 
  • trunk/Library/Set.fss

    r1786 r1825  
    8585    es.generate[\Set[\E\]\](Union[\E\], 
    8686                                fn (e:E): Set[\E\] => singleton[\E\](e)) 
    87 opr BIG {[\T extends StandardTotalOrder[\T\]\] 
    88          g: ( Reduction[\SomeList\], T->SomeList) -> SomeList } : Set[\T\] = 
    89     set(covariantComprehension[\T\](g)) 
    90  
    91 opr BIG UNION[\R extends StandardTotalOrder[\R\]\](g:(Reduction[\Set[\R\]\], Set[\R\]->Set[\R\])->Set[\R\]): 
    92                     Set[\R\] = g(Union[\R\], identity[\R\]) 
     87opr BIG {[\T extends StandardTotalOrder[\T\]\]} : Set[\T\] = 
     88    covariantComprehension[\T,Set[\T\]\](fn x => set(x)) 
     89 
     90opr BIG UNION[\R extends StandardTotalOrder[\R\]\](): BigReduction[\Set[\R\],Set[\R\]\] = 
     91    BigReduction[\Set[\R\],Set[\R\]\](Union[\R\]) 
    9392 
    9493object Union[\E extends StandardTotalOrder[\E\]\] extends CommutativeMonoidReduction[\Set[\E\]\] 
     
    9897end 
    9998 
    100 opr BIG INTERSECTION[\R extends StandardTotalOrder[\R\]\](g:(Reduction[\Maybe[\Set[\R\]\]\], 
    101                              Set[\R\]->Maybe[\Set[\R\]\]) -> 
    102                             Maybe[\Set[\R\]\]): Set[\R\] = 
    103     Intersection[\R\].unlift(g(Intersection[\R\], 
    104                                fn (s:Set[\R\]):Just[\Set[\R\]\] => 
    105                                    Intersection[\R\].lift(s))) 
     99opr BIG INTERSECTION[\R extends StandardTotalOrder[\R\]\](): 
     100        BigReduction[\Set[\R\],AnyMaybe\] = 
     101    BigReduction[\Set[\R\],AnyMaybe\](Intersection[\R\]) 
    106102 
    107103object Intersection[\E extends StandardTotalOrder[\E\]\] 
  • trunk/ProjectFortress/demos/wordcount.fss

    r1712 r1825  
    7171        a.union(fn(_,x,y)=>x+y, b) 
    7272 
    73 opr BIG UNIONSUM(g:(Reduction[\Map[\CaseInsensitiveString,ZZ32\]\], 
    74                     Map[\CaseInsensitiveString,ZZ32\]->Map[\CaseInsensitiveString,ZZ32\]) -> 
    75                    Map[\CaseInsensitiveString,ZZ32\]): Map[\CaseInsensitiveString,ZZ32\] = 
    76     embiggen[\Map[\CaseInsensitiveString,ZZ32\]\](fn (a,b) => a UNIONSUM b, 
    77                                             mapping[\CaseInsensitiveString,ZZ32\](), g) 
     73opr BIG UNIONSUM(): BigReduction[\Map[\CaseInsensitiveString,ZZ32\], 
     74                                 Map[\CaseInsensitiveString,ZZ32\]\] = 
     75    embiggen[\Map[\CaseInsensitiveString,ZZ32\]\]( 
     76        fn (a,b) => a UNIONSUM b, {[\CaseInsensitiveString,ZZ32\]}) 
    7877 
    7978opr UNIONUNION(a:Map[\ZZ32,List[\String\]\], b:Map[\ZZ32, List[\String\]\]):Map[\ZZ32,List[\String\]\] = 
    8079    a.union(fn(k,x,y) =>x.append(y),b) 
    8180 
    82 opr BIG UNIONUNION(g:(Reduction[\Map[\ZZ32,List[\String\]\]\], 
    83                       Map[\ZZ32,List[\String\]\]->Map[\ZZ32,List[\String\]\]) -> 
    84                      Map[\ZZ32,List[\String\]\]): Map[\ZZ32,List[\String\]\] = 
    85     embiggen[\Map[\ZZ32, List[\String\]\]\](fn(a,b) => a UNIONUNION b, 
    86                                     mapping[\ZZ32,List[\String\]\](),g) 
     81opr BIG UNIONUNION(): BigReduction[\Map[\ZZ32, List[\String\]\],Map[\ZZ32, List[\String\]\]\] = 
     82    embiggen[\Map[\ZZ32, List[\String\]\]\](fn(a,b) => a UNIONUNION b, {[\ZZ32,List[\String\]\]}) 
    8783 
    8884processFile(name:String):() = do 
  • trunk/ProjectFortress/demos/zeno.fss

    r1700 r1825  
    4444 **) 
    4545 
    46 rounds : ZZ32 = 2
     46rounds : ZZ32 = 1
    4747 
    4848(** Represents m / 2^n and 2 - (m / 2^n) **) 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/values/OverloadedFunction.java

    r1800 r1825  
    251251            Overload o1 = new_overloads.get(i); 
    252252            Fcn fn = o1.getFn(); 
    253             if (fn instanceof GenericFunctionalMethod) { 
    254                 // Any reason not to just ignore these? 
    255                 // They never get type info, right? 
    256                 // continue; 
    257             } else { 
     253            if (!(fn instanceof FGenericFunction)) { 
    258254                FType ty = fn.type(); 
    259                 ftalist.add(ty); 
     255                if (ty != null) ftalist.add(ty); 
    260256            } 
    261257 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/Desugarer.java

    r1810 r1825  
    10401040        int i = gens.size(); 
    10411041        if (i==0) { 
    1042             /* Boolean guard */ 
     1042            /* Single generator as body, with no generator clauses. */ 
    10431043            body = new TightJuxt(span, false, 
    1044                              Useful.list(GENERATE_NAME,body,redVar,unitVar)); 
     1044                             Useful.list(GENERATE_NAME, 
     1045                                         ExprFactory.makeTuple(body,redVar,unitVar))); 
    10451046        } else { 
    10461047            body = new TightJuxt(body.getSpan(), false, 
     
    10591060                          OpName op, Expr body, List<StaticArg> staticArgs) { 
    10601061        body = visitGenerators(span, gens, body); 
    1061         Expr res = ExprFactory.makeOpExpr(span,op,body,staticArgs); 
     1062        Expr opexp = ExprFactory.makeOpExpr(span,op,staticArgs); 
     1063        Expr res = new TightJuxt(span, false, 
     1064                                 Useful.list(BIGOP_NAME, 
     1065                                             ExprFactory.makeTuple(opexp,body))); 
    10621066        // System.out.println("Desugared to "+res.toStringVerbose()); 
    10631067        return (Expr)visitNode(res); 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ExprFactory.java

    r1685 r1825  
    318318    } 
    319319 
     320    public static OpExpr makeOpExpr(Span span, OpName op, List<StaticArg> staticArgs) { 
     321        return new OpExpr(span, false, makeOpRef(op, staticArgs)); 
     322    } 
     323 
    320324    public static OpExpr makeOpExpr(Span span, OpName op, Expr arg, 
    321325                                      List<StaticArg> staticArgs) { 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/Span.java

    r1710 r1825  
    123123        if (file_names_differ || begin.getLine() != end.getLine() 
    124124                || left_col != right_col) { 
    125             w.append(Printer.tilde); 
     125            w.append(printer ? Printer.tilde : "-"); 
    126126            if (file_names_differ) { 
    127127                if (printer) w.append("\""); 
  • trunk/ProjectFortress/tests/HeapTest.fss

    r1786 r1825  
    6666object TestReduction extends AssociativeReduction[\(ZZ32,ZZ32,ZZ32)\] 
    6767    getter toString(): String = "HeapTest.TestReduction" 
     68    simpleJoin(a:Any, b:Any): Any = fail("Bogus non-tuple data in TestReduction") 
    6869    simpleJoin(a:(ZZ32,ZZ32,ZZ32), b:(ZZ32,ZZ32,ZZ32)):(ZZ32,ZZ32,ZZ32) = do 
    6970        (mn_a,sz_a,mx_a) = a 
     
    8384        Just[\(ZZ32,ZZ32,ZZ32)\](k,1,k) 
    8485      end 
    85     (mn,sz,mx) = h.generate[\Maybe[\(ZZ32,ZZ32,ZZ32)\]\](TestReduction, sing).getDefault(0,0,0) 
     86    (mn,sz,mx) = h.generate[\AnyMaybe\](TestReduction, sing).getDefault(0,0,0) 
    8687    assert(n,sz," size versus computed size") 
    8788    if (sz > 0) then 
  • trunk/ProjectFortress/tests/MapExprTest.fss

    r1389 r1825  
    2222 
    2323opr { |->[\ K,V \] xs: (K,V)... }: Map[\K,V\] = Map[\K,V\] 
    24 opr BIG {|->[\K,V,T\] g: (Reduction[\Map[\K,V\]\], T -> Map[\K,V\]) -> Map[\K,V\] }: Map[\K,V\] = Map[\K,V\] 
     24opr BIG {|->[\K,V,T\] }: Map[\K,V\] = Map[\K,V\] 
    2525 
    2626run(args:String...):() = () 
  • trunk/ProjectFortress/tests/WordCountSmall.fss

    r1712 r1825  
    2626isDelimiter(c:Char):Boolean =   c IN <| ' ',  ',', '.', '?' |> 
    2727 
    28 maybeAddWord(word:String,  
     28maybeAddWord(word:String, 
    2929                         database:Map[\String,ZZ32\]):Map[\String,ZZ32\]= do 
    3030    var result:Map[\String,ZZ32\] := mapping[\String,ZZ32\]() 
    3131    occurs = database.member(word,0) 
    32     if occurs > 0 then  
     32    if occurs > 0 then 
    3333        result := database.update(word,occurs+1) 
    34     else  
     34    else 
    3535        result := database.add(word,1) 
    3636    end 
     
    7373opr UNIONSUM(a:Map[\String,ZZ32\], b:Map[\String,ZZ32\]):Map[\String,ZZ32\] = a.union(fn(k,x,y)=>x+y, b) 
    7474 
    75 opr BIG UNIONSUM(g:(Reduction[\Map[\String,ZZ32\]\], Map[\String,ZZ32\]->Map[\String,ZZ32\])->Map[\String,ZZ32\]):Map[\String,ZZ32\]= 
    76     embiggen[\Map[\String,ZZ32\]\](fn (a,b) => a UNIONSUM b, mapping[\String,ZZ32\](), g) 
     75opr BIG UNIONSUM(): BigReduction[\Map[\String,ZZ32\], 
     76                                 Map[\String,ZZ32\]\] = 
     77    embiggen[\Map[\String,ZZ32\]\](fn (a,b) => a UNIONSUM b, {[\String,ZZ32\]}) 
    7778 
    78 opr UNIONUNION(a:Map[\ZZ32,List[\String\]\], b:Map[\ZZ32, List[\String\]\]):Map[\ZZ32,List[\String\]\] = a.union(fn(k,x,y) =>x.append(y),b) 
     79opr UNIONUNION(a:Map[\ZZ32,List[\String\]\], b:Map[\ZZ32, List[\String\]\]):Map[\ZZ32,List[\String\]\] = 
     80    a.union(fn(k,x,y) =>x.append(y),b) 
    7981 
    80 opr BIG UNIONUNION(g:(Reduction[\Map[\ZZ32,List[\String\]\]\], Map[\ZZ32,List[\String\]\]->Map[\ZZ32,List[\String\]\])->Map[\ZZ32,List[\String\]\]):Map[\ZZ32,List[\String\]\] = 
    81     embiggen[\Map[\ZZ32, List[\String\]\]\](fn(a,b) => a UNIONUNION b, mapping[\ZZ32,List[\String\]\](),g
     82opr BIG UNIONUNION(): BigReduction[\Map[\ZZ32, List[\String\]\],Map[\ZZ32, List[\String\]\]\] = 
     83    embiggen[\Map[\ZZ32, List[\String\]\]\](fn(a,b) => a UNIONUNION b, {[\ZZ32,List[\String\]\]}
    8284 
    8385processFile(name:String):() = do 
    8486    println("Processing file " name) 
    8587    var rs:FileReadStream = FileReadStream(name) 
     88    rs.close() 
    8689    database:Map[\String, ZZ32\] = BIG UNIONSUM [l<-rs.lines()] (getWords(l)) 
    8790    var invDatabase:Map[\ZZ32,List[\String\]\] = BIG UNIONUNION [(x,y) <-database] (makeInv(x,y)) 
    88     try  
    89         for i <- seq(1#100) do  
     91    try 
     92        for i <- seq(1#100) do 
    9093            (c:ZZ32,m:List[\String\]) = invDatabase.maximum().get() 
    9194            invDatabase := invDatabase.deleteMaximum() 
    92             println(m ": " c " times")  
    93         end  
    94     catch e  
     95            println(m ": " c " times") 
     96        end 
     97    catch e 
    9598            NotFound => println("end") 
    9699    end 
    97     rs.close() 
    98100end 
    99101 
    100102 
    101103run(args:String...)= do 
    102     processFile(getEnvironment("fortress.autohome", ".") "/ProjectFortress/tests/presidents")    
     104    processFile(getEnvironment("fortress.autohome", ".") "/ProjectFortress/tests/presidents") 
    103105end 
    104106end 
  • trunk/ProjectFortress/tests/simpleBig.fss

    r1505 r1825  
    2020export Executable 
    2121 
    22 opr BIG STAR[\T\](g:(Reduction[\Number\],T->Number)->Number):Number
    23     g(SumReduction,cast[\Number\]) 
     22opr BIG STAR[\T extends Number\](): Comprehension[\T,Number,Number,Number\]
     23    Comprehension[\T,Number,Number,Number\](fn x => x, SumReduction, cast[\Number\]) 
    2424 
    2525run(args:String...):() = do