structure TaskPriority = struct type priority = int val compare = Int.compare type item = int * real val priority : item -> int = #1 end structure PQ = LeftPriorityQFn (TaskPriority) val seed = Random.rand (19,21) val Ntasks = 100000 val Nprio = 100 val _ = let val tasks = List.tabulate (Ntasks, fn (i) => let val prio = Int.mod (Random.randNat seed, Nprio) val r = Real.fromInt i in (prio, r) end) val pq = foldl PQ.insert PQ.empty tasks (* or val pq = PQ.fromList tasks *) fun aux pq' = case PQ.next pq' of NONE => () | SOME ((prio, r), pq'') => ( print (Int.toString prio ^ ", " ^ (Real.toString r) ^ "\n"); aux pq'' ) in aux pq end