Alice
started 10/10/2003; 4:03:19 AM - last post 10/18/2003; 5:34:15 AM
|
|
Manuel Simoni - Alice
10/10/2003; 4:03:19 AM (reads: 8417, responses: 21)
|
|
Alice |
Alice is a functional programming language based on Standard ML, extended with support for concurrent, distributed, and constraint programming.
Alice builds on our experience with developing the Mozart system. The current version of Alice is based on the Mozart virtual machine. Alice programs can therefore interoperate with Oz.
I found the tour, especially the section on distribution, very interesting.
Posted to functional by Manuel Simoni on 10/10/03; 4:13:33 AM
|
|
|
|
Isaac Gouy - Re: Alice
10/10/2003; 8:20:16 AM (reads: 796, responses: 0)
|
|
|
|
Even if this has been discussed before, this still gives me a chance to ask anyone who has used both Prolog and Alice how much Alice's "futures" compare to Prolog-style logic variables.
|
|
|
There are actually three kinds of futures in alice:
- concurrent futures which represent the result of a thread
- lazy futures which execute the expression on demand when requested
- promised futures which can be fulfilled explicitly.
Promised future somewhat resemble logic variables from prolog, but
the interface is made explicit.
The actual interface is:
signature PROMISE =
sig
type 'a promise
type 'a t = 'a promise
exception Promise
val promise : unit -> 'a promise
val future : 'a promise -> 'a
val fulfill : 'a promise * 'a -> unit
val fail : 'a promise * exn -> unit
end
They are for example used in alice to implement locks:
structure Lock :>
sig
type lock
type t = lock
val lock : unit -> lock
val sync : lock -> ('a -> 'b) -> ('a -> 'b)
end
=
struct
type lock = unit ref
type t = lock
fun lock () = ref ()
fun sync lock f x =
let
val p = Promise.promise ()
val u = Ref.exchange (lock, Promise.future p)
val _ = Future.await u
val y = f x handle e => (Promise.fulfill (p, ()); raise e)
in
Promise.fulfill (p, ()); y
end
end
|
|
Patrick Logan - Re: Alice
10/13/2003; 10:10:30 AM (reads: 478, responses: 1)
|
|
Is the main difference between an Alice future and a Prolog logic variable something like this:
A future will have one value at some (future) time in the computation, and it will retain that value from that time forward.
Whereas in Prolog, a logic variable will have zero or more values over time, based on the truth of the expression that contains the variable and the database used to unify values to logic variables in that expression.
|
|
Ehud Lamm - Re: Alice
10/13/2003; 10:19:31 AM (reads: 490, responses: 0)
|
|
I am not sure I follow, but it seems a future is just like a delayed expression in Scheme. No?
|
|
|
Yes both Patrick and Ehud got it right. The main difference
between futures and scheme delayed expressions is that
force is implicit in Alice. That is any value can potentially
be a future.
|
|
|
Sorry somehow konqueror did not update the page correctly :-(
|
|
Ehud Lamm - Re: Alice
10/13/2003; 12:24:31 PM (reads: 458, responses: 0)
|
|
No prob. I deleted all the extra messages.
|
|
Frank Atanassow - Re: Alice
10/14/2003; 8:29:12 AM (reads: 373, responses: 1)
|
|
Whereas in Prolog, a logic variable will have zero or more values over time, based on the truth of the expression that contains the variable and the database used to unify values to logic variables in that expression.
A Prolog variable has zero or one value: you can't unify two values (ground terms) unless they're equal.
|
|
Ehud Lamm - Re: Alice
10/14/2003; 10:45:22 AM (reads: 373, responses: 0)
|
|
Does that take into account backtracking?
|
|
Darius Bacon - Re: Alice
10/17/2003; 12:03:04 PM (reads: 310, responses: 0)
|
|
I am not sure I follow, but it seems a future is just like a delayed expression in Scheme. No?
From my reading of the tour, Alice does have lazy expressions like that (only with implicit forcing, as Benedikt Grundmann pointed out) -- but futures are not quite the same thing. You can fulfill the future at any time, including concurrently. You can `fail' the future with an exception to indicate failure. And trying to implicitly force an unfulfilled future blocks the current thread.
This is almost the same as E's promises -- trying to force an unresolved promise in E raises an exception instead of blocking, since E has event-loop concurrency instead of threads. E has a 'when-catch' construct to wait for a reference to become more resolved. (I like E's terminology here better than Alice's: you resolve or clobber a promise instead of fulfilling or failing a future.) Note that you can resolve a promise with another promise, like unifying two logic variables.
The earliest I've heard of this general idea was Arvind's I-structures, I think...
|
|
|
Given the decision to use implicit forcing in Alice it was "logical" to use
"blocking" with regard to unfulfilled futures. Alice features the
ability to write highly concurrent programms and using "blocking" eliminates
the need for many conventional thread synchronizing primitives like
barriers. For example
val a = Array.tabulate (1000, fn i => spawn ... some big computation...)
val sum = Array.foldl op+ 0 a
+ will "block" until it's operands are available.
|
|
|
|