Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/tests/nofib/real/anna/sebastian1.cor

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.



list a ::= Nil | Cons a (list a);

;;

lid l = case l of Nil -> l; Cons x xs -> l end;
  {abstract identity on 4}

foldr f a l 
  = case l of
       Nil -> lid a; 
       Cons x xs -> f x (foldr f a xs)
    end;
{
map f
  = foldr (\a b -> Cons (f a) b) Nil;


sum
  = foldr (\x y -> x + y) 0;

length xs
  = sum (map (\a -> 1) xs);

lengthRec l
  = case l of
       Nil -> 0;
       Cons x xs -> 1 + lengthRec xs
    end;
}

{  foldr  (2,4):   Anna307FT -- 7 approxes, 2062 evals   }

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].