News for hackers. Stuff that matters.
Re:Writing a DSL with Python by gaius on Monday September 07, 2009 @08:48AM (#809064)
Because functional languages discourage loops. This is just a really trivial example, but:

    # value x =[|1;2;3;4|];
    value x : array int = [|1; 2; 3; 4|]
    # for i = 0 to (Array.length x) - 1 do {
      Printf.printf "%d" x.(i);
      };
    1234- : unit = ()
    # Array.iter (fun y -> Printf.printf "%d" y) x;
    1234- : unit = ()
Basically the entire body of any for loop I would want to make an anonymous function. Then if I cared about the result I could do:

    # Array.map (fun y -> Printf.printf "%d" y) x;
    1234- : array unit = [|(); (); (); ()|]

Assuming the underlying platform supported it, and the function is pure, that's "free" parallelism.

There are no comments on this comment yet.