Help for this page

Select Code to Download


  1. or download this
    fun sum [ ] = 0
      | sum (h::t) = h + (sum t);
    
    fun length [ ] = 0
      | length (h::t) = 1 + (length t);
    
  2. or download this
    multi sub sum ()          returns Int { 0             }
    multi sub sum (*$x, *@xs) returns Int { $x + sum(@xs) }
    
    multi sub length ()          returns Int { 0               }
    multi sub length (*$x, *@xs) returns Int { 1 + length(@xs) }
    
  3. or download this
    sub sum {
        return 0 unless @_;
    ...
        shift;
        return 1 + length(@_);
    }