Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
29
Task/Catamorphism/Ada/catamorphism.ada
Normal file
29
Task/Catamorphism/Ada/catamorphism.ada
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
with Ada.Text_IO;
|
||||
|
||||
procedure Catamorphism is
|
||||
|
||||
type Fun is access function (Left, Right: Natural) return Natural;
|
||||
type Arr is array(Natural range <>) of Natural;
|
||||
|
||||
function Fold_Left (F: Fun; A: Arr) return Natural is
|
||||
Result: Natural := A(A'First);
|
||||
begin
|
||||
for I in A'First+1 .. A'Last loop
|
||||
Result := F(Result, A(I));
|
||||
end loop;
|
||||
return Result;
|
||||
end Fold_Left;
|
||||
|
||||
function Max (L, R: Natural) return Natural is (if L > R then L else R);
|
||||
function Min (L, R: Natural) return Natural is (if L < R then L else R);
|
||||
function Add (Left, Right: Natural) return Natural is (Left + Right);
|
||||
function Mul (Left, Right: Natural) return Natural is (Left * Right);
|
||||
|
||||
package NIO is new Ada.Text_IO.Integer_IO(Natural);
|
||||
|
||||
begin
|
||||
NIO.Put(Fold_Left(Min'Access, (1,2,3,4)), Width => 3);
|
||||
NIO.Put(Fold_Left(Max'Access, (1,2,3,4)), Width => 3);
|
||||
NIO.Put(Fold_Left(Add'Access, (1,2,3,4)), Width => 3);
|
||||
NIO.Put(Fold_Left(Mul'Access, (1,2,3,4)), Width => 3);
|
||||
end Catamorphism;
|
||||
Loading…
Add table
Add a link
Reference in a new issue