Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

More philosophy about one of the most important disadvantage of functional programming..

5 views
Skip to first unread message

Amine Moulay Ramdane

unread,
May 30, 2021, 3:40:41 PM5/30/21
to
Hello,


More philosophy about one of the most important disadvantage of functional programming..

I am a white arab and i think i am smart since i have also invented many scalable algorithms and algorithms..

I have just posted previously my thoughts about continuation—passing style (CPS) and Monads, here they are:

https://groups.google.com/g/alt.comp.lang.borland-delphi/c/kdP6YSTcjj4

I think i am smart and i have just "quickly" noticed that when you are
using patterns of functional programming such as Map and Monads ,
it will come with a very important disadvantage, and it is that you will move much more the data from a memory region to another memory region,
so it is not efficient, since it is really slower, and i think that
it is the one of the most important disadvantage of functional programming, since functional programming abstracts more, but it is really slower, so i have just given you previously an example of a "Maybe" Monad in Delphi, and here is an example of the "List" Monad in Delphi and notice how it is is really slower by moving the data to the the returned result of the "Bind" function of the Monad as TmList object:


program List_monad;

{$APPTYPE CONSOLE}

uses
System.SysUtils;

type
TmList = record
Value: TArray<Integer>;
function ToString: string;
function Bind(f: TFunc<TArray<Integer>, TmList>): TmList;
end;

function Create(aValue: TArray<Integer>): TmList;
begin
Result.Value := copy(aValue, 0, length(aValue));
end;

{ TmList }

function TmList.Bind(f: TFunc<TArray<Integer>, TmList>): TmList;
begin
Result := f(self.Value);
end;

function TmList.ToString: string;
var
i: Integer;
begin
Result := '[ ';
for i := 0 to length(value) - 1 do
begin
if i > 0 then
Result := Result + ', ';
Result := Result + value[i].toString;
end;
Result := Result + ']';
end;

function Increment(aValue: TArray<Integer>): TmList;
var
i: integer;
begin
SetLength(Result.Value, length(aValue));
for i := 0 to High(aValue) do
Result.Value[i] := aValue[i] + 1;
end;

function Double(aValue: TArray<Integer>): TmList;
var
i: integer;
begin
SetLength(Result.Value, length(aValue));
for i := 0 to High(aValue) do
Result.Value[i] := aValue[i] * 2;
end;

var
ml1, ml2: TmList;

begin
ml1 := Create([3, 4, 5]);
ml2 := ml1.Bind(Increment).Bind(double);
Writeln(ml1.ToString, ' -> ', ml2.ToString);
readln;
end.


Output:
[ 3, 4, 5] -> [ 8, 10, 12]


Thank you,
Amine Moulay Ramdane.
0 new messages