Can anyone help me with this issue please?

Can anyone help me with this issue please?
This project can not be compiled (Delphi XE8 Update 1): http://www49.zippyshare.com/v/Ws9cdzJY/file.html
[dcc32 Fatal Error] uMapParallel.pas(94): F2084 Internal Error: C27720
Pastebin: http://pastebin.com/RwZCq4Z4
http://www49.zippyshare.com/v/Ws9cdzJY/file.html

Comments

  1. XE: Doesn't compile.

    XE7: [dcc32 Fatal Error] uMapParallel.pas(95): F2084 Internal Error: C26701

    XE8: [dcc32 Fatal Error] uMapParallel.pas(95): F2084 Internal Error: C27720

    ReplyDelete
  2. Maybe my reply is off topic but this is not real map operation. Map should be able to return a new type.
    Last time I checked, proper map or flatMap for generic types cannot be done in Delphi. Due to this shortcoming, it is impossible to use some basic FP concepts in Delphi.

    ReplyDelete
  3. Linas Naginionis
    I take a leaf out of PHP array_map: http://php.net/manual/en/function.array-map.php where in/out types are the same. And what do you mean? Please show me an example.

    ReplyDelete
  4. I don't use php, but real map operation should be as follows (e.g. for IEnumerable):
    function IEnumerable.Map(const mapper: TFunc): IEnumerable;
    flatMap:
    function IEnumerable.FlatMap(const mapper: TFunc>): IEnumerable;

    ReplyDelete
  5. Linas Naginionis Of course it is possible (lets not argue about the the syntax and how verbose the code looks compared to doing that in an FPL). You just need to specify the input and output type and the transformation delegate:

    function Map(const input: TArray; const f: TFunc): TArray;

    So Map([1,2,3,4,5], Power) returns [1,4,9,16,25]

    Nonamed Pravdin Move the record type out of TMapParallel and make it TIndexedRecord. You can still define a nested alias TIndexedRecord = TIndexedRecord inside of TMapParallel so the rest of the code stays as it is. Also please report this to quality.embarcadero.com

    ReplyDelete
  6. Yes, of course it does (see Spring.Collections.TCollections.Select). The issue I described in this post was something different (returning X> from a method of type X)

    ReplyDelete
  7. Stefan Glienke No, it's the same issue. Just try to implement the methods I described previously. And I'm not talking about static class functions. I got the same compiler error recently trying to do so.

    ReplyDelete
  8. Stefan Glienke Where are flatMap and map methods which should be defined in IEnumerable in your example? You can't even compare this to Java 8 , your example looks so funny and weird :) Your approach is not composable. The whole point of map and flatMap (and monads in general) is composition and following the happy path. You don't need to fight against the language if it does not allow to do some things properly, IMO.

    ReplyDelete
  9. FlatMap and Map require a returntype different from the input type which is why these methods cannot be part of an interface which cannot have parameterized methods - you should know that. I already told you that we don't need to argue over the verbosity of the Delphi syntax. It does not need map, flatmap and collect since that is what SelectMany does (see https://msdn.microsoft.com/en-us/library/system.linq.enumerable.selectmany(v=vs.110).aspx)

    ReplyDelete
  10. Stefan Glienke
    Thank you very much. Now it compiles fine. But if I change "Source: TArray" to "Source: array of T" in TMapParallel.Map, I get (inside TParallel.For() lambda): [dcc32 Error] uMapParallel.pas(70): E2555 Cannot capture symbol 'Source'. Is it a bug, or not?

    ReplyDelete
  11. Nonamed Pravdin More of a limitation that is by design. Some things cannot be captured into an anonymous method.

    ReplyDelete

Post a Comment