5. Features of interest
Mathematical rendering
Parallelism
Software transactional memory
Operator and function overloading
Objects / traits
Contracts
Components / apis
Wednesday, July 1, 2009
7. Types
ZZ32, ZZ64 - signed integer types
RR32, RR64 - floating point types
String
Boolean
Wednesday, July 1, 2009
8. juxtaposition
3 4 evaluates to 12
“a” “b” evaluates to “ab”
log 1 evaluates to 0
Wednesday, July 1, 2009
9. Ranges
5:9 evaluates to [5,6,7,8,9]
5:9:2 evaluates to [5,7,9]
5#2 evaluates to [5,6]
Wednesday, July 1, 2009
10. Variables
Immutable: name[:type] = value
zero = 0
zero:ZZ32 = 0
Mutable: var name[:type] = value
OR name[:type] := value
var sum = 0
sum := 0
Wednesday, July 1, 2009
12. A simple example
component fact
export Executable
fact(n:ZZ32): ZZ32 =
if n = 0 then 1
else n fact(n-1)
end
run():()=do
for k<-seq(1:10) do
println " fact(" k ") = " fact(k)
end
end
end
Executable - a trait juxtaposition as operator
defining run()
Parallelism - in terms, in for
Rendering: ZZ32, <-, fonts
seq() - force sequential
Wednesday, July 1, 2009
13. BIG ideas
But factorial is just a big multiply...use aggregate PROD
operator ∏ instead.
This is known as a BIG operator.
Wednesday, July 1, 2009
14. More direct implementation
component factp
export Executable
factp(n:ZZ32): ZZ32 =
PROD [i <- 1:n] i
run():()=do
for k<-seq(1:10) do
println " factp(" k ") = " factp(k)
end
end
end
PROD = aggregate Known as “BIG”
product operators
SUM = summation You can make your own!
Wednesday, July 1, 2009
15. Operator overloading
Would be nice to actually use the right mathematical
operator ! instead of a function, wouldn’t it?
Wednesday, July 1, 2009
16. Let’s make it an operator
component facto
export Executable
opr(n:ZZ32)! = PROD [i <- 1:n] i
run():()=do
for k<-seq(1:10) do
println k "! = " k!
end
end
end
opr() used to define a Also can do prefix, infix,
postfix operator here nofix, multifix, or
enclosing!
Wednesday, July 1, 2009
18. Another example
component sos
import List.{...}
export Executable
sumOfSquares(n:List[ZZ32]): ZZ64 = do
sum:ZZ64 := 0
for i<-0#|n| do
sum += (n[i])^2
end
sum
end
run():()=do
theList = <|[ZZ32] x | x<-1#100|>
println "sumOfSquares = "
sumOfSquares(theList)
end
end
What’s the bug? (Hint: think parallelism)
Wednesday, July 1, 2009
19. Implicit parallelism
Many things implicitly parallel
for loops
parameters to a function call
do ... also ... end construct
Here, for loop is parallel, so sum += is a data race
Use atomic to fix
Wednesday, July 1, 2009
20. Atomic punk
component sos
import List.{...} Fortress uses Software
export Executable
Transactional Memory
sumOfSquares(n:List[ZZ32]): ZZ64 = do
atomic blocks executed all
sum:ZZ64 := 0
for i<-0#|n| do
or nothing
atomic sum += (n[i])^2
end
sum
Retry on collision
end
run():()=do
theList = <|[ZZ32] x | x<-1#100|>
println "sumOfSquares = " Transactions may nest
sumOfSquares(theList)
end
tryatomic
end
Wednesday, July 1, 2009
21. Traits
component traitexample
export Executable
trait - like Java interface
trait Animal
talk():String
end methods - abstract or
trait Fuzzy concrete
howFuzzy():String
end
object - like Java final class
trait Cat extends Animal
fields, methods
getter name():String
talk() = "meow"
end
object Whiskers extends {Cat, Fuzzy} constructors
name() = "Whiskers"
howFuzzy() = "real fuzzy"
end multiple inheritance
run():() = do
w:Whiskers = Whiskers getter / setter - metadata
println w.name() " is " w.howFuzzy()
end
end
Wednesday, July 1, 2009
22. Function contracts
component factc
export Executable Documentation of
factorial(n:ZZ32):ZZ32 semantic constraints
requires { n >= 0 }
ensures { outcome >= 0 } beyond the type system.
= PROD [i <- 1:n] i
run():() = do requires - specifies pre-
conditions on incoming
for k<-seq(1:10) do
println k "! = " factorial(k)
arguments
end
end
end
ensures - specifies post-
condition on “outcome”
Wednesday, July 1, 2009
23. Components and APIs
Components modularize your program
Components export and import APIs (NEVER other
components, just APIs)
APIs are explicitly defined in their own file type
Repository for components
Wednesday, July 1, 2009
24. And more...
Literal arrays, multi-dimensional arrays
Maps, sets, skip lists, trees, heaps, sparse vectors and matrices,
quick sort, etc in library
Explicit thread spawn, memory region tree
Function overloading
Tuples
Tests
Functions as first class objects
Exceptions
Wednesday, July 1, 2009
25. Whither next?
Currently working on compiler
Goal is to have it working in 6 months for a real
bioinformatics project
Wednesday, July 1, 2009
26. For more...
Project Home: http://projectfortress.sun.com/Projects/
Community
David Chase: http://www.infoq.com/presentations/
chase-fortress
Guy Steele, Eric Allen: http://tinyurl.com/md6f6g
Wednesday, July 1, 2009
27. Alex Miller
Twitter: http://twitter.com/puredanger
Blog: http://tech.puredanger.com
Presentations: http://slideshare.net/alexmiller
Wednesday, July 1, 2009