Recommendations on avoiding range pipeline type hell

Patrick Schluter Patrick.Schluter at bbox.fr
Sun May 16 12:49:19 UTC 2021


On Sunday, 16 May 2021 at 09:55:31 UTC, Chris Piker wrote:
> On Sunday, 16 May 2021 at 09:17:47 UTC, Jordan Wilson wrote:
>
>> Another example:
>> ```d
>> auto r = [iota(1,10).map!(a => a.to!int),iota(1,10).map!(a => 
>> a.to!int)];
>> # compile error
>> ```
> Hi Jordan
>
> Nice succinct example.  Thanks for looking at the code :)
>
> So, honest question.  Does it strike you as odd that the exact 
> same range definition is considered to be two different types?

     Even in C
     ```
     typedef struct {
         int a;
     } type1;
     ```
     and
     ```
     struct {
         int a;
     } type2;
     ```

are two different types. The compiler will give an error if you 
pass one to a function waiting for the other.

```
void fun(type1 v)
{
}

type2 x;

fun(x);  // gives error
```
See https://godbolt.org/z/eWenEW6q1
>
> Maybe that's eminently reasonable to those with deep knowledge, 
> but it seems crazy to a new D programmer.  It breaks a general 
> assumption about programming when copying and pasting a 
> definition yields two things that aren't the same type. (except 
> in rare cases like SQL where null != null.)



>
> On a side note, I appreciate that `.array` solves the problem, 
> but I'm writing pipelines that are supposed to work on 
> arbitrarily long data sets (> 1.4 TB is not uncommon).




More information about the Digitalmars-d-learn mailing list