October 12, 2021

On Monday, 11 October 2021 at 15:59:10 UTC, Atila Neves wrote:

>

I'm brainstorming about what I'll talk about at DConf, and during a conversation with Walter I thought it might be cool to talk about:

  • Worst features implemented in a non-toy language
  • Worst features (in your opinion) in D
  • Features you'd like to see in D

Ideas? Examples?

Thanks!

Not necessarily a feature, but I think the absence of hindley milner type inference is a big one. I think that statically typed languages should adopt it or at the very least be influenced by it unless they have a really good reason not too.

Types are completely optional in (vanilla) hindley milner. You can write code that looks like python and still have all the benefits of static typing. It also infers the most general type for the code you write. This makes your code as generic as possible unless you add a type annotation to make it less generic.

I also think that it can help in language design in general. Weak typing and subtyping, features that are generally disliked are incompatible with hindley milner. It gives good answers to what the type of a null pointer and an empty array are without resorting to void pointers and void arrays which feel hacky.

October 13, 2021
On 13/10/2021 3:06 AM, Superstar64 wrote:
> Not necessarily a feature, but I think the absence of hindley milner type inference is a big one. I think that statically typed languages should adopt it or at the very least be influenced by it unless they have a really good reason not too.

Hey hey hey, ML strikes again!

ML + C syntax would have been a realllll winner back in the 70's I reckon, or today cos ya know that is the direction we are all going in.
October 12, 2021

On Tuesday, 12 October 2021 at 06:14:40 UTC, bauss wrote:

>

On Tuesday, 12 October 2021 at 03:17:08 UTC, SealabJaster wrote:

>

abc => { return 123; } should not be returning a function that returns a function.

I agree with this so much, like why couldn't it have been made so you had to be explicit if you wanted to return a function? Like:

abc => &{ return 123; }

But you are do it explicitly, use the more verbose syntax:

alias a = abc => function{ return 123; };

Also you have warning now

>

Deprecation: Using (args) => { ... } to create a delegate that returns a delegate is error-prone.

October 12, 2021
On Monday, 11 October 2021 at 21:21:21 UTC, Paul Backus wrote:
> The real missing piece here IMO is DIP 1038 [1]. Once it is fully accepted and implemented, defining a Result type will be trivial.

Could you explain how @nodiscard would help with sum types? Presumably it won't help to implicitly convert a subtype into the wrapper sum type?
October 12, 2021

On Tuesday, 12 October 2021 at 13:26:34 UTC, Steven Schveighoffer wrote:

>

On 10/12/21 8:42 AM, bauss wrote:

>

Yeah, but I would rather that it was still allowed and that the semantics just changed.

But obviously for good reason that isn't happening since it would break existing code.

What would you change it to?

IMO the actual answer here is to deprecate the { /* ... */ } syntax for function literals entirely.

Not only is it confusing in the context of => lambdas, it also creates a grammatical ambiguity between function literals and block statements, which results in bugs like issue 21619.

October 12, 2021

On Tuesday, 12 October 2021 at 16:19:42 UTC, Nick Treleaven wrote:

>

On Monday, 11 October 2021 at 21:21:21 UTC, Paul Backus wrote:

>

The real missing piece here IMO is DIP 1038 [1]. Once it is fully accepted and implemented, defining a Result type will be trivial.

Could you explain how @nodiscard would help with sum types? Presumably it won't help to implicitly convert a subtype into the wrapper sum type?

Currently, the big advantage exceptions have over sum types is that you cannot accidentally ignore an exception. Either you catch it, or it crashes your program.

With @nodiscard, we can eliminate this advantage, and put sum types and exceptions on an equal playing field.

October 12, 2021

On Tuesday, 12 October 2021 at 16:26:33 UTC, Paul Backus wrote:

>

On Tuesday, 12 October 2021 at 16:19:42 UTC, Nick Treleaven wrote:

>

On Monday, 11 October 2021 at 21:21:21 UTC, Paul Backus wrote:

>

The real missing piece here IMO is DIP 1038 [1]. Once it is fully accepted and implemented, defining a Result type will be trivial.

Could you explain how @nodiscard would help with sum types? Presumably it won't help to implicitly convert a subtype into the wrapper sum type?

Currently, the big advantage exceptions have over sum types is that you cannot accidentally ignore an exception. Either you catch it, or it crashes your program.

With @nodiscard, we can eliminate this advantage, and put sum types and exceptions on an equal playing field.

One idea I had when bumping into this problem was something like a with statement but you give it some kind of composition operator, and then it joins the statements up implicitly a la do notation in Haskell

October 12, 2021

On Tuesday, 12 October 2021 at 17:25:52 UTC, max haughton wrote:

>

One idea I had when bumping into this problem was something like a with statement but you give it some kind of composition operator, and then it joins the statements up implicitly a la do notation in Haskell

You can technically do this already with foreach and opApply, although the result ends up looking kind of goofy:

foreach (b; a)
foreach (c; b)
foreach (d; c)
e;

Desugars to:

a.opApply(b =>
    b.opApply(c =>
        c.opApply(d => e)));

...which is almost the same thing as Haskell's do notation, if you replace >>= with opApply and x <- y with foreach (x, y).

This similarity is perhaps why Scala uses the for keyword for its version of do notation.

October 12, 2021

On 10/12/21 12:22 PM, Paul Backus wrote:

>

On Tuesday, 12 October 2021 at 13:26:34 UTC, Steven Schveighoffer wrote:

>

On 10/12/21 8:42 AM, bauss wrote:

>

Yeah, but I would rather that it was still allowed and that the semantics just changed.

But obviously for good reason that isn't happening since it would break existing code.

What would you change it to?

IMO the actual answer here is to deprecate the { /* ... */ } syntax for function literals entirely.

Not only is it confusing in the context of => lambdas, it also creates a grammatical ambiguity between function literals and block statements, which results in bugs like issue 21619.

It's not a terrible idea. But I think there are hacks all over the place that enjoy the short syntax. One that I know of is to get the parent scope of a location:

alias parentScope = __traits(parent, {});

Now, changing this to __traits(parent, (){}) probably isn't a horrible update to require, but this code breakage is going to seem a little extraneous.

-Steve

October 12, 2021

On Tuesday, 12 October 2021 at 17:49:10 UTC, Steven Schveighoffer wrote:

>

It's not a terrible idea. But I think there are hacks all over the place that enjoy the short syntax. One that I know of is to get the parent scope of a location:

alias parentScope = __traits(parent, {});

Now, changing this to __traits(parent, (){}) probably isn't a horrible update to require, but this code breakage is going to seem a little extraneous.

This syntax is cute, but it's also extremely opaque, and confusing to beginners [1][2]. (){} is not much better, but it at least makes it clear that what you're looking at isn't a normal block statement, and you need to check the documentation/ask in the Learn forum/etc. to find out what it is.

[1] https://forum.dlang.org/post/rzboijdfewehucrmztyc@forum.dlang.org
[2] https://forum.dlang.org/post/i40s2i$271n$1@digitalmars.com