Changeset 1825
- Timestamp:
- 06/06/08 17:43:51 (6 months ago)
- Files:
-
- trunk/Library/FortressLibrary.fsi (modified) (2 diffs)
- trunk/Library/FortressLibrary.fss (modified) (16 diffs)
- trunk/Library/List.fsi (modified) (2 diffs)
- trunk/Library/List.fss (modified) (1 diff)
- trunk/Library/Map.fss (modified) (1 diff)
- trunk/Library/PureList.fss (modified) (1 diff)
- trunk/Library/Set.fss (modified) (2 diffs)
- trunk/ProjectFortress/demos/wordcount.fss (modified) (1 diff)
- trunk/ProjectFortress/demos/zeno.fss (modified) (1 diff)
- trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/values/OverloadedFunction.java (modified) (1 diff)
- trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/Desugarer.java (modified) (2 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ExprFactory.java (modified) (1 diff)
- trunk/ProjectFortress/src/com/sun/fortress/nodes_util/Span.java (modified) (1 diff)
- trunk/ProjectFortress/tests/HeapTest.fss (modified) (2 diffs)
- trunk/ProjectFortress/tests/MapExprTest.fss (modified) (1 diff)
- trunk/ProjectFortress/tests/WordCountSmall.fss (modified) (2 diffs)
- trunk/ProjectFortress/tests/simpleBig.fss (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Library/FortressLibrary.fsi
r1810 r1825 500 500 __generate[\E,R\](g:Generator[\E\], r: Reduction[\R\], b:E->R): R 501 501 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 502 505 (* Not currently used for desugaring, but will be used in future. 503 506 __nest[\E1,E2\](g:Generator[\E1\], f:E1->Generator[\E2\]):Generator[\E2\] … … 1445 1448 end 1446 1449 1447 trait BigOperator[\I, R,L\]1450 trait BigOperator[\I,O,R,L\] 1448 1451 abstract getter reduction(): ActualReduction[\R,L\] 1449 1452 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 1454 end 1455 1456 object BigReduction[\R,L\](r:ActualReduction[\R,L\]) extends BigOperator[\R,R,R,L\] 1453 1457 getter reduction(): ActualReduction[\R,L\] 1454 1458 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 1460 end 1461 1462 object Comprehension[\I,O,R,L\](u: R->O, r: ActualReduction[\R,L\], singleton:I->R) 1463 extends BigOperator[\I,O,R,L\] 1459 1464 getter reduction(): ActualReduction[\R,L\] 1460 1465 getter body(): I->R 1466 getter unwrap(): R->O 1461 1467 end 1462 1468 trunk/Library/FortressLibrary.fss
r1810 r1825 620 620 SimpleNestedGenerator[\E,G\](self,f) 621 621 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 622 628 (** Cross product of two generators. This is specifically 623 629 designed to be overloaded, such that pairs of independent … … 699 705 700 706 (** 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. **) 705 712 __map[\E,R\](g:Generator[\E\], f:E->R): Generator[\R\] = 706 713 typecase g of 714 SomeMappedGenerator[\E\] => g.map[\R\](f) 707 715 SequentialGenerator[\E\] => SimpleMappedSeqGenerator[\E,R\](g,f) 708 716 else => SimpleMappedGenerator[\E,R\](g,f) 709 717 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 710 737 711 738 trait SequentialGenerator[\E\] extends { Generator[\E\] } … … 770 797 opr IN(x:E, self):Boolean = cond[\Boolean\](fn (e:E):Boolean => x=e, fn () => false) 771 798 end 799 800 (** Conjunction and disjunction of condition functions **) 801 opr 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 **) 805 opr ORCOND[\I\](p1:I->Condition[\()\], p2:I->Condition[\()\]): I->Condition[\()\] = 806 fn (i:I):Boolean => p1(i).holds() OR: p2(i).holds() 772 807 773 808 (** Operations which use generation internally. Should be functional … … 2159 2194 empty(): L 2160 2195 join(a: L, b: L): L 2161 lift(r: R): L2196 lift(r: Any): L 2162 2197 unlift(l:L): R 2163 2198 (** If this reduction left-distributes over r, return a pair of 2164 2199 reductions with the same lift and unlift **) 2165 leftDistribute(r: Reduction[\R\]): Maybe[\(Reduction[\R\],Reduction[\R\])\] =2200 leftDistribute(r: Reduction[\R\]): SomeReductionPair[\R\] = 2166 2201 distribute(r) 2167 2202 (** If this reduction right-distributes over r, return a pair of 2168 2203 reductions with the same lift and unlift **) 2169 rightDistribute(r: Reduction[\R\]): Maybe[\(Reduction[\R\],Reduction[\R\])\] =2204 rightDistribute(r: Reduction[\R\]): SomeReductionPair[\R\] = 2170 2205 distribute(r) 2171 2206 (** If this reduction distributes over r, return a pair of 2172 2207 reductions with the same lift and unlift **) 2173 distribute (r: Reduction[\R\]): Maybe[\(Reduction[\R\],Reduction[\R\])\] =2174 No thing[\(Reduction[\R\],Reduction[\R\])\]2208 distribute[\K\](r: ActualReduction[\R,K\]): SomeReductionPair[\R\] = 2209 NoReductionPair[\R\] 2175 2210 end 2176 2211 … … 2197 2232 2198 2233 (** The usual lifting to Maybe for identity-less operators **) 2199 trait AssociativeReduction[\R\] extends ActualReduction[\R, Maybe[\R\]\]2234 trait AssociativeReduction[\R\] extends ActualReduction[\R,AnyMaybe\] 2200 2235 empty(): Nothing[\R\] = Nothing[\R\] 2201 join(a: Maybe[\R\], b: Maybe[\R\]): Maybe[\R\]=2236 join(a: AnyMaybe, b: AnyMaybe): AnyMaybe = 2202 2237 if av <- a then 2203 2238 if bv <- b then 2204 Just [\R\](simpleJoin(av,bv))2239 Just(simpleJoin(av,bv)) 2205 2240 else 2206 2241 a … … 2209 2244 b 2210 2245 end 2211 simpleJoin(a: R, b:R): R2212 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() 2214 2249 end 2215 2250 … … 2218 2253 (** Monoids don't require a special lift and unlift operation. **) 2219 2254 trait MonoidReduction[\R\] extends ActualReduction[\R,R\] 2220 lift(r: R): R = r2255 lift(r:Any): R = r 2221 2256 unlift(r:R): R = r 2222 2257 end … … 2230 2265 end 2231 2266 2232 trait BigOperator[\I, R,L\]2267 trait BigOperator[\I,O,R,L\] 2233 2268 getter reduction(): ActualReduction[\R,L\] 2234 2269 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 2271 end 2272 2273 object BigReduction[\R,L\](r:ActualReduction[\R,L\]) extends BigOperator[\R,R,R,L\] 2238 2274 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 2277 end 2278 2279 object Comprehension[\I,O,R,L\](u: R->O, r: ActualReduction[\R,L\], singleton:I->R) 2280 extends BigOperator[\I,O,R,L\] 2244 2281 getter reduction(): ActualReduction[\R,L\] = r 2245 2282 getter body(): I->R = singleton 2283 getter unwrap(): R->O = u 2246 2284 end 2247 2285 … … 2263 2301 end 2264 2302 2265 opr SUM[\T \](g:(Reduction[\Number\],T->Number)->Number): Number=2266 g(SumReduction,cast[\Number\])2303 opr SUM[\T extends Number\](): Comprehension[\T,Number,Number,Number\] = 2304 Comprehension[\T,Number,Number,Number\](fn x => x, SumReduction, cast[\Number\]) 2267 2305 2268 2306 object ProdReduction extends CommutativeMonoidReduction[\Number\] … … 2272 2310 end 2273 2311 2274 opr PROD[\T \](g:(Reduction[\Number\],T->Number)->Number): Number=2275 g(ProdReduction,cast[\Number\])2312 opr PROD[\T extends Number\](): Comprehension[\T,Number,Number,Number\] = 2313 Comprehension[\T,Number,Number,Number\](fn x => x, ProdReduction, cast[\Number\]) 2276 2314 2277 2315 object MinReduction[\T extends StandardMin[\T\]\] extends CommutativeReduction[\T\] 2278 2316 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 2318 end 2319 2320 opr BIG MIN[\T extends StandardMin[\T\]\](): BigReduction[\T,AnyMaybe\] = 2321 BigReduction[\T,AnyMaybe\](MinReduction[\T\]) 2285 2322 2286 2323 object MaxReduction[\T extends StandardMax[\T\]\] extends CommutativeReduction[\T\] 2287 2324 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 2326 end 2327 2328 opr BIG MAX[\T extends StandardMax[\T\]\](): BigReduction[\T,AnyMaybe\] = 2329 BigReduction[\T,AnyMaybe\](MaxReduction[\T\]) 2330 2331 opr 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 2335 opr 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)) 2302 2338 2303 2339 (** AndReduction and OrReduction take advantage of natural zeroes for early exit. **) … … 2311 2347 end 2312 2348 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 2349 opr BIG AND[\T\](): BigReduction[\Boolean,Boolean\] = 2350 BigReduction[\Boolean,Boolean\](AndReduction) 2322 2351 2323 2352 object OrReduction … … 2330 2359 end 2331 2360 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 2361 opr BIG OR[\T\]():BigReduction[\Boolean, Boolean\] = 2362 BigReduction[\Boolean,Boolean\](OrReduction) 2341 2363 2342 2364 (** A reduction performing String concatenation **) … … 2357 2379 object NewlineReduction extends AssociativeReduction[\String\] 2358 2380 getter toString() = "StringReduction" 2359 simpleJoin(a :String, b:String): String= a // b2381 simpleJoin(a, b) = a // b 2360 2382 end 2361 2383 2362 2384 (** This operator performs string concatenation, first converting 2363 2385 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) 2386 opr BIG ||(): String = 2387 Comprehension[\Any,String,String,String\]( 2388 identity[\String\],StringReduction,fn (x:Any)=> "" x) 2366 2389 2367 2390 (** This operator performs string concatenation, first converting 2368 2391 its inputs (of type Any) to String if necessary, and separating 2369 2392 non-empty components by a space. **) 2370 opr BIG |||(g:(Reduction[\String\],Any->String)->String): String = 2371 g(SpaceReduction, fn (x:Any)=> "" x) 2393 opr BIG |||(): Comprehension[\Any,String,String,String\] = 2394 Comprehension[\Any,String,String,String\]( 2395 identity[\String\],SpaceReduction,fn (x:Any)=> "" x) 2372 2396 2373 2397 (** This operator performs string concatenation with newline 2374 2398 separation, first converting its inputs (of type Any) to String if 2375 2399 necessary. **) 2376 opr BIG //(g:(Reduction[\Maybe[\String\]\],Any->Maybe[\String\])->Maybe[\String\]): String = 2377 g(NewlineReduction, fn (x:Any)=> Just[\String\]("" x)).get() 2400 opr BIG //(): Comprehension[\Any,String,AnyMaybe,AnyMaybe\] = 2401 Comprehension[\Any,String,AnyMaybe,AnyMaybe\]( 2402 fn x => x,NewlineReduction,fn (x:Any)=> "" x) 2378 2403 2379 2404 (** A %MapReduceReduction% takes an associative binary function %j% on … … 2403 2428 g(MIOprReduction[\T,OP\](z), fn (x) => x) 2404 2429 *) 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)2430 embiggen[\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) 2407 2432 2408 2433 (** Helpers for maps and cross products of generators. These can be … … 2410 2435 outwards if we think that'd be useful), but let's get this much 2411 2436 working first. *) 2412 2413 trait MappedGenerator[\E,F\] extends Generator[\F\] 2437 trait SomeMappedGenerator[\F\] extends Generator[\F\] end 2438 2439 trait MappedGenerator[\E,F\] extends SomeMappedGenerator[\F\] 2414 2440 getter g(): Generator[\E\] 2415 2441 getter f(): E -> F … … 2456 2482 getter toString() = "seq(" g0 ".map(f))" 2457 2483 seq(self): SimpleMappedSeqGenerator[\E,F\] = self 2484 end 2485 2486 trait 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()) 2497 end 2498 2499 object SimpleFilterGenerator[\E\](g0:Generator[\E\], p0: E->Condition[\()\]) 2500 extends FilterGenerator[\E\] 2501 getter g(): Generator[\E\] = g0 2502 getter p(): E -> Condition[\()\] = p0 2503 end 2504 2505 object 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 2458 2511 end 2459 2512 trunk/Library/List.fsi
r1786 r1825 115 115 opr <|[\E\] xs: E... |>: List[\E\] 116 116 (** List comprehensions: *) 117 opr BIG <|[\T\] g: ( Reduction[\SomeList\], T->SomeList) -> SomeList |>: List[\T\]117 opr BIG <|[\T\]|>:Comprehension[\T,List[\T\],List[\T\],List[\T\]\] 118 118 119 119 (** Convert generator into list (simpler type than comprehension above): *) … … 139 139 (** Utility for cooking up covariant comprehensions of other 140 140 (non-covariant) types. **) 141 covariantComprehension[\T \]( g: (Reduction[\SomeList\], T->SomeList) -> SomeList): List[\T\]141 covariantComprehension[\T,R\](unwrap:List[\T\]->R): Comprehension[\T,R,List[\T\],List[\T\]\] 142 142 143 143 end trunk/Library/List.fss
r1786 r1825 176 176 (** Vararg factory for lists; provides aggregate list constants **) 177 177 opr <|[\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\]()) 178 opr BIG <|[\T\]|>: Comprehension[\T,List[\T\],SomeList,SomeList\] = 179 covariantComprehension[\T,List[\T\]\](fn (x) => x) 180 181 covariantComprehension[\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) 183 184 184 185 (** Convert generator into list; can be used to desugar list trunk/Library/Map.fss
r1786 r1825 158 158 mapping[\Key,Val\](xs) 159 159 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) 160 opr BIG {|->[\Key,Val\] } : Comprehension[\(Key,Val),Map[\Key,Val\],SomeList,SomeList\] = 161 covariantComprehension[\(Key,Val),Map[\Key,Val\]\](fn g => mapping(g)) 162 163 opr 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 166 opr 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\]) 173 168 174 169 object SeqMapGenerator[\Key,Val\](o:Map[\Key,Val\]) trunk/Library/PureList.fss
r1786 r1825 80 80 (** Vararg factory for lists; provides aggregate list constants **) 81 81 opr <|[\E\] xs: E... |>: List[\E\] = list(xs) 82 opr BIG <|[\T\] g: ( Reduction[\SomeList\], T->SomeList) -> SomeList|>: List[\T\] =83 list(covariantComprehension[\T\](g))82 opr BIG <|[\T\]|>: Comprehension[\T,List[\T\],SomeList,SomeList\] = 83 covariantComprehension[\T,List[\T\]\](fn x => list(x)) 84 84 85 85 (** Convert generator into list; can be used to desugar list trunk/Library/Set.fss
r1786 r1825 85 85 es.generate[\Set[\E\]\](Union[\E\], 86 86 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\]) 87 opr BIG {[\T extends StandardTotalOrder[\T\]\]} : Set[\T\] = 88 covariantComprehension[\T,Set[\T\]\](fn x => set(x)) 89 90 opr BIG UNION[\R extends StandardTotalOrder[\R\]\](): BigReduction[\Set[\R\],Set[\R\]\] = 91 BigReduction[\Set[\R\],Set[\R\]\](Union[\R\]) 93 92 94 93 object Union[\E extends StandardTotalOrder[\E\]\] extends CommutativeMonoidReduction[\Set[\E\]\] … … 98 97 end 99 98 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))) 99 opr BIG INTERSECTION[\R extends StandardTotalOrder[\R\]\](): 100 BigReduction[\Set[\R\],AnyMaybe\] = 101 BigReduction[\Set[\R\],AnyMaybe\](Intersection[\R\]) 106 102 107 103 object Intersection[\E extends StandardTotalOrder[\E\]\] trunk/ProjectFortress/demos/wordcount.fss
r1712 r1825 71 71 a.union(fn(_,x,y)=>x+y, b) 72 72 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) 73 opr BIG UNIONSUM(): BigReduction[\Map[\CaseInsensitiveString,ZZ32\], 74 Map[\CaseInsensitiveString,ZZ32\]\] = 75 embiggen[\Map[\CaseInsensitiveString,ZZ32\]\]( 76 fn (a,b) => a UNIONSUM b, {[\CaseInsensitiveString,ZZ32\]}) 78 77 79 78 opr UNIONUNION(a:Map[\ZZ32,List[\String\]\], b:Map[\ZZ32, List[\String\]\]):Map[\ZZ32,List[\String\]\] = 80 79 a.union(fn(k,x,y) =>x.append(y),b) 81 80 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) 81 opr 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\]\]}) 87 83 88 84 processFile(name:String):() = do trunk/ProjectFortress/demos/zeno.fss
r1700 r1825 44 44 **) 45 45 46 rounds : ZZ32 = 2046 rounds : ZZ32 = 10 47 47 48 48 (** Represents m / 2^n and 2 - (m / 2^n) **) trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/values/OverloadedFunction.java
r1800 r1825 251 251 Overload o1 = new_overloads.get(i); 252 252 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)) { 258 254 FType ty = fn.type(); 259 ftalist.add(ty);255 if (ty != null) ftalist.add(ty); 260 256 } 261 257 trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/Desugarer.java
r1810 r1825 1040 1040 int i = gens.size(); 1041 1041 if (i==0) { 1042 /* Boolean guard*/1042 /* Single generator as body, with no generator clauses. */ 1043 1043 body = new TightJuxt(span, false, 1044 Useful.list(GENERATE_NAME,body,redVar,unitVar)); 1044 Useful.list(GENERATE_NAME, 1045 ExprFactory.makeTuple(body,redVar,unitVar))); 1045 1046 } else { 1046 1047 body = new TightJuxt(body.getSpan(), false, … … 1059 1060 OpName op, Expr body, List<StaticArg> staticArgs) { 1060 1061 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))); 1062 1066 // System.out.println("Desugared to "+res.toStringVerbose()); 1063 1067 return (Expr)visitNode(res); trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ExprFactory.java
r1685 r1825 318 318 } 319 319 320 public static OpExpr makeOpExpr(Span span, OpName op, List<StaticArg> staticArgs) { 321 return new OpExpr(span, false, makeOpRef(op, staticArgs)); 322 } 323 320 324 public static OpExpr makeOpExpr(Span span, OpName op, Expr arg, 321 325 List<StaticArg> staticArgs) { trunk/ProjectFortress/src/com/sun/fortress/nodes_util/Span.java
r1710 r1825 123 123 if (file_names_differ || begin.getLine() != end.getLine() 124 124 || left_col != right_col) { 125 w.append( Printer.tilde);125 w.append(printer ? Printer.tilde : "-"); 126 126 if (file_names_differ) { 127 127 if (printer) w.append("\""); trunk/ProjectFortress/tests/HeapTest.fss
r1786 r1825 66 66 object TestReduction extends AssociativeReduction[\(ZZ32,ZZ32,ZZ32)\] 67 67 getter toString(): String = "HeapTest.TestReduction" 68 simpleJoin(a:Any, b:Any): Any = fail("Bogus non-tuple data in TestReduction") 68 69 simpleJoin(a:(ZZ32,ZZ32,ZZ32), b:(ZZ32,ZZ32,ZZ32)):(ZZ32,ZZ32,ZZ32) = do 69 70 (mn_a,sz_a,mx_a) = a … … 83 84 Just[\(ZZ32,ZZ32,ZZ32)\](k,1,k) 84 85 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) 86 87 assert(n,sz," size versus computed size") 87 88 if (sz > 0) then trunk/ProjectFortress/tests/MapExprTest.fss
r1389 r1825 22 22 23 23 opr { |->[\ 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\]24 opr BIG {|->[\K,V,T\] }: Map[\K,V\] = Map[\K,V\] 25 25 26 26 run(args:String...):() = () trunk/ProjectFortress/tests/WordCountSmall.fss
r1712 r1825 26 26 isDelimiter(c:Char):Boolean = c IN <| ' ', ',', '.', '?' |> 27 27 28 maybeAddWord(word:String, 28 maybeAddWord(word:String, 29 29 database:Map[\String,ZZ32\]):Map[\String,ZZ32\]= do 30 30 var result:Map[\String,ZZ32\] := mapping[\String,ZZ32\]() 31 31 occurs = database.member(word,0) 32 if occurs > 0 then 32 if occurs > 0 then 33 33 result := database.update(word,occurs+1) 34 else 34 else 35 35 result := database.add(word,1) 36 36 end … … 73 73 opr UNIONSUM(a:Map[\String,ZZ32\], b:Map[\String,ZZ32\]):Map[\String,ZZ32\] = a.union(fn(k,x,y)=>x+y, b) 74 74 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) 75 opr BIG UNIONSUM(): BigReduction[\Map[\String,ZZ32\], 76 Map[\String,ZZ32\]\] = 77 embiggen[\Map[\String,ZZ32\]\](fn (a,b) => a UNIONSUM b, {[\String,ZZ32\]}) 77 78 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) 79 opr 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) 79 81 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)82 opr 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\]\]}) 82 84 83 85 processFile(name:String):() = do 84 86 println("Processing file " name) 85 87 var rs:FileReadStream = FileReadStream(name) 88 rs.close() 86 89 database:Map[\String, ZZ32\] = BIG UNIONSUM [l<-rs.lines()] (getWords(l)) 87 90 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 90 93 (c:ZZ32,m:List[\String\]) = invDatabase.maximum().get() 91 94 invDatabase := invDatabase.deleteMaximum() 92 println(m ": " c " times") 93 end 94 catch e 95 println(m ": " c " times") 96 end 97 catch e 95 98 NotFound => println("end") 96 99 end 97 rs.close()98 100 end 99 101 100 102 101 103 run(args:String...)= do 102 processFile(getEnvironment("fortress.autohome", ".") "/ProjectFortress/tests/presidents") 104 processFile(getEnvironment("fortress.autohome", ".") "/ProjectFortress/tests/presidents") 103 105 end 104 106 end trunk/ProjectFortress/tests/simpleBig.fss
r1505 r1825 20 20 export Executable 21 21 22 opr BIG STAR[\T \](g:(Reduction[\Number\],T->Number)->Number):Number=23 g(SumReduction,cast[\Number\])22 opr BIG STAR[\T extends Number\](): Comprehension[\T,Number,Number,Number\] = 23 Comprehension[\T,Number,Number,Number\](fn x => x, SumReduction, cast[\Number\]) 24 24 25 25 run(args:String...):() = do
