summaryrefslogblamecommitdiff
path: root/test/files/pos/t0031.scala
blob: d4050c8184417698950fcd9048f7a0ec4a0f2e5a (plain) (tree)
1
2
3
4
5
6
7





                                                  
                                                                        




                                                              
                                                     


                 
                                         







                                               
                               


     
object Main {

    trait Ensure[a] {
        def ensure(postcondition: a => Boolean): a
    }

    def require[a](precondition: => Boolean)(command: => a): Ensure[a] =
        if (precondition)
            new Ensure[a] {
	        def ensure(postcondition: a => Boolean): a = {
	            val result = command;
	            if (postcondition(result)) result
	            else sys.error("Assertion error")
                }
	    }
        else
            sys.error("Assertion error");

    def arb[a](s: List[a]) =
        require (! s.isEmpty) {
           s.head
        } ensure (result => s contains result);

    def main(args: Array[String]) = {
    	val s = List(1, 2);
        Console.println(arb(s))
    }

}