-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHistogramExample.scala
More file actions
40 lines (35 loc) · 1.14 KB
/
HistogramExample.scala
File metadata and controls
40 lines (35 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package ilc
package examples
import feature._
class HistogramExample
extends Example
with MapReduce
with integers.SyntaxSugar
with integers.AbelianDerivation
with integers.ToScala
{
// userMap : ℤ → Bag ℤ → Bag (ℤ × ℤ)
// userMap = λ ignoredDocumentID : ℤ.
// foldGroup freeAbelianGroup
// (λ number : ℤ. singleton (pair number 1))
val userMap: UntypedTerm = 'ignoredDocumentId ->: FoldGroup(FreeAbelianGroup,
'number ->: Singleton(Pair('number, LiteralInt(1))))
// userReduce : ℤ → Bag ℤ → ℤ
// userReduce = λ ignoredKey : ℤ.
// foldGroup additiveGroupOnIntegers (λx : ℤ. x)
val userReduce = 'ignoredKey ->: FoldGroup(additiveGroupOnIntegers, 'x ->: 'x)
// program : Map ℤ (Bag ℤ) → Map ℤ ℤ
// program =
// mapReduce
// freeAbelianGroup
// additiveGroupOnIntegers
// userMap
// userReduce
val untypedProgram: UntypedTerm =
mapReduce(
FreeAbelianGroup,
additiveGroupOnIntegers,
userMap,
userReduce) ofType MapType(ℤ, BagType(ℤ)) =>: MapType(ℤ, ℤ)
val program: Term = untypedTermToTerm(untypedProgram)
}