Project Fortress
-
Upload
alex-miller -
Category
Technology
-
view
3.886 -
download
2
description
Transcript of Project Fortress
Alex MillerProject Fortress
http://www.flickr.com/photos/micbaun/1216608114/Wednesday, July 1, 2009
Dude, isn’t Fortress like FORTRAN or something?
http://www.flickr.com/photos/finkle/3111290180/Wednesday, July 1, 2009
Um, no.
Wednesday, July 1, 2009
Modern language design
+
Scientific computing
Wednesday, July 1, 2009
Features of interest
Mathematical rendering
Parallelism
Software transactional memory
Operator and function overloading
Objects / traits
Contracts
Components / apis
Wednesday, July 1, 2009
Let’s build some basics
Wednesday, July 1, 2009
Types
ZZ32, ZZ64 - signed integer types
RR32, RR64 - floating point types
String
Boolean
Wednesday, July 1, 2009
juxtaposition
3 4 evaluates to 12
“a” “b” evaluates to “ab”
log 1 evaluates to 0
Wednesday, July 1, 2009
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
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
Now you’re dangerous.
Wednesday, July 1, 2009
A simple examplecomponent factexport 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) endend
end
Executable - a trait defining run()
Rendering: ZZ32, <-, fonts
juxtaposition as operator
Parallelism - in terms, in for
seq() - force sequential
Wednesday, July 1, 2009
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
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) endend
end
More direct implementation
PROD = aggregate product
SUM = summation
Known as “BIG” operators
You can make your own!
Wednesday, July 1, 2009
Operator overloading
Would be nice to actually use the right mathematical operator ! instead of a function, wouldn’t it?
Wednesday, July 1, 2009
component factoexport Executable
opr(n:ZZ32)! = PROD [i <- 1:n] i
run():()=do for k<-seq(1:10) do println k "! = " k! endend
end
Let’s make it an operator
opr() used to define a postfix operator here
Also can do prefix, infix, nofix, multifix, or enclosing!
Wednesday, July 1, 2009
Lists
evens = <|[\ZZ32\] 2,4,6,8,10|> println "evens: " evens
evens2 = <|[\ZZ32\] 2 x | x <- 1:5|>println "evens2: " evens2
odds = <|[\ZZ32\] e - 1 | e <- evens |>println "odds: " odds
evens: <|2, 4, 6, 8, 10|>
evens2: <|2, 4, 6, 8, 10|>
odds: <|1, 3, 5, 7, 9|>
Wednesday, July 1, 2009
Another example
What’s the bug? (Hint: think parallelism)
component sosimport List.{...}export Executable
sumOfSquares(n:List[\ZZ32\]): ZZ64 = do sum:ZZ64 := 0 for i<-0#|n| do sum += (n[i])^2 end sumend
run():()=do theList = <|[\ZZ32\] x | x<-1#100|> println "sumOfSquares = " sumOfSquares(theList)end
end
Wednesday, July 1, 2009
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
Atomic punkcomponent sosimport List.{...}export Executable
sumOfSquares(n:List[\ZZ32\]): ZZ64 = do sum:ZZ64 := 0 for i<-0#|n| do atomic sum += (n[i])^2 end sumend
run():()=do theList = <|[\ZZ32\] x | x<-1#100|> println "sumOfSquares = " sumOfSquares(theList)end
end
Fortress uses Software Transactional Memory
atomic blocks executed all or nothing
Retry on collision
Transactions may nest
tryatomic
Wednesday, July 1, 2009
Traits
trait - like Java interface
methods - abstract or concrete
object - like Java final class
fields, methods
constructors
multiple inheritance
getter / setter - metadata
component traitexampleexport Executable
trait Animal talk():Stringend
trait Fuzzy howFuzzy():Stringend
trait Cat extends Animal getter name():String talk() = "meow"end
object Whiskers extends {Cat, Fuzzy} name() = "Whiskers" howFuzzy() = "real fuzzy"end
run():() = do w:Whiskers = Whiskers println w.name() " is " w.howFuzzy()endend
Wednesday, July 1, 2009
Function contracts
Documentation of semantic constraints beyond the type system.
requires - specifies pre-conditions on incoming arguments
ensures - specifies post-condition on “outcome”
component factcexport Executable
factorial(n:ZZ32):ZZ32 requires { n >= 0 } ensures { outcome >= 0 } = PROD [i <- 1:n] i
run():() = do for k<-seq(1:10) do println k "! = " factorial(k) endendend
Wednesday, July 1, 2009
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
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
Whither next?
Currently working on compiler
Goal is to have it working in 6 months for a real bioinformatics project
Wednesday, July 1, 2009
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
Alex Miller
Twitter: http://twitter.com/puredanger
Blog: http://tech.puredanger.com
Presentations: http://slideshare.net/alexmiller
Wednesday, July 1, 2009