This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I was reading through these examples: http://apocalisp.wordpress.com/2010/06/08/type-level-programming-in-scala/ | |
// and I thought it would be nice to more quickly get to something useful, to show the power of the techniques. | |
object SizedListExample { | |
// Type of all Non-negative integers | |
sealed trait Nat | |
// This is zero. | |
sealed trait _0 extends Nat | |
// Successor to some non-negative number | |
sealed trait Succ[N <: Nat] extends Nat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.{BlockingQueue, ArrayBlockingQueue, CountDownLatch, Executors, TimeUnit} | |
/* | |
Abstracts away the common pattern of producing items into a queue that are | |
consumed concurrently by a pool of workers. | |
*/ | |
class ConcurrentBlockingQueueConsumer[T](queue: BlockingQueue[T], producer: Iterator[T], concurrencyLevel: Int) { | |
lazy val pool = Executors.newFixedThreadPool(concurrencyLevel) | |
def run()(consumer: (T) => Unit) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* defines the Ast.binding for a function of form: | |
let fun_name ?(opt_arg1) ?(opt_arg2) final_ident = function_body ... | |
*) | |
let function_with_label_args _loc ~fun_name ~final_ident ~function_body ~return_type opt_args = | |
let opt_args = opt_args @ [ <:patt< $lid:final_ident$ >> ] in | |
let rec fn _loc = function (* could lose _loc and use List.fold_right *) | |
|hd::tl -> <:expr< function $hd$ -> $fn _loc tl$ >> | |
|[] -> <:expr< ( $function_body$ : $return_type$ ) >> | |
in | |
<:binding< $lid:fun_name$ = $fn _loc opt_args$ >> |