Thread overview | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 06, 2018 sumtype 0.3.0 | ||||
---|---|---|---|---|
| ||||
SumType is a generic sum type for modern D. It is meant as an alternative to `std.variant.Algebraic`. Features: - Pattern matching, including support for structural matching (*) - Self-referential types, using `This` - Works with `pure`, `@safe`, `@nogc`, and `immutable` (*) - Zero runtime overhead compared to hand-written C - No heap allocation - Does not rely on runtime type information (`TypeInfo`) (*) Starred features (*) are those that are missing from `Algebraic`. Code examples are available in the documentation (linked below). New in this release: - The list of types allowed in a sum type is now public - Implicit qualifier conversions are now allowed in pattern matching - Better code examples in the documentation This library is a work in progress. If you have a use case you'd like to see supported, or an API you'd like to see implemented, please get in touch! Documentation: https://pbackus.github.io/sumtype/sumtype.html DUB: https://code.dlang.org/packages/sumtype Github: https://github.com/pbackus/sumtype |
May 06, 2018 Re: sumtype 0.3.0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | On 05/06/2018 03:18 PM, Paul Backus wrote:
> SumType is a generic sum type for modern D. It is meant as an alternative to `std.variant.Algebraic`.
>
Very nice! I may use this.
|
May 07, 2018 Re: sumtype 0.3.0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | On Sunday, 6 May 2018 at 19:18:02 UTC, Paul Backus wrote: > SumType is a generic sum type for modern D. It is meant as an alternative to `std.variant.Algebraic`. > > Features: > - Pattern matching, including support for structural matching (*) > - Self-referential types, using `This` > - Works with `pure`, `@safe`, `@nogc`, and `immutable` (*) > - Zero runtime overhead compared to hand-written C > - No heap allocation > - Does not rely on runtime type information (`TypeInfo`) (*) > > Starred features (*) are those that are missing from `Algebraic`. > > Code examples are available in the documentation (linked below). > > New in this release: > - The list of types allowed in a sum type is now public > - Implicit qualifier conversions are now allowed in pattern matching > - Better code examples in the documentation > > This library is a work in progress. If you have a use case you'd like to see supported, or an API you'd like to see implemented, please get in touch! > > Documentation: https://pbackus.github.io/sumtype/sumtype.html > DUB: https://code.dlang.org/packages/sumtype > Github: https://github.com/pbackus/sumtype Nice. I've written something similar in LightAlgebraic at https://github.com/nordlow/phobos-next/blob/master/src/vary.d#L30 which is also significantly faster than `std.typecons.Algebraic`. Has the same features as SumType except for - Self-referential types, using `This` and - pattern matching Note that the `memoryPacked` flag being `true` hasn't been thoroughly tested. Your're free to copy an ideas or features in `LightAlgebraic` into `SumType`. |
May 07, 2018 Re: sumtype 0.3.0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | On Sunday, 6 May 2018 at 19:18:02 UTC, Paul Backus wrote:
> SumType is a generic sum type for modern D. It is meant as an alternative to `std.variant.Algebraic`.
>
> Features:
> - Pattern matching, including support for structural matching (*)
> - Self-referential types, using `This`
> - Works with `pure`, `@safe`, `@nogc`, and `immutable` (*)
> - Zero runtime overhead compared to hand-written C
> - No heap allocation
> - Does not rely on runtime type information (`TypeInfo`) (*)
>
> Starred features (*) are those that are missing from `Algebraic`.
>
> Code examples are available in the documentation (linked below).
>
> New in this release:
> - The list of types allowed in a sum type is now public
> - Implicit qualifier conversions are now allowed in pattern matching
> - Better code examples in the documentation
>
> This library is a work in progress. If you have a use case you'd like to see supported, or an API you'd like to see implemented, please get in touch!
>
> Documentation: https://pbackus.github.io/sumtype/sumtype.html
> DUB: https://code.dlang.org/packages/sumtype
> Github: https://github.com/pbackus/sumtype
I spent several hours trying to get this working with a non-trivial AST, and I think that it just isn't going to work until the compiler front-end gets better about handling recursive definitions. It fails in more-or-less the same way that my attempts at using std.variant did, and this is not the fault of your library.
It's too bad, because the visitor pattern is not very good when you want to support visitors that should not accidentally modify the tree (i.e. arguments to `visit` are `const`), and other visitors whose job is to re-write the tree.
|
May 07, 2018 Re: sumtype 0.3.0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brian Schott | On Monday, 7 May 2018 at 09:23:04 UTC, Brian Schott wrote: > I spent several hours trying to get this working with a non-trivial AST, and I think that it just isn't going to work until the compiler front-end gets better about handling recursive definitions. It fails in more-or-less the same way that my attempts at using std.variant did, and this is not the fault of your library. > > It's too bad, because the visitor pattern is not very good when you want to support visitors that should not accidentally modify the tree (i.e. arguments to `visit` are `const`), and other visitors whose job is to re-write the tree. Thanks for taking a look! There are definitely compiler issues that keep this (and Algebraic) from being as useful as they could be (e.g., issue 1807 [1]), though so far, I've managed to find workarounds for the ones I ran into. I'd be curious to see the code that was giving you trouble, if you still have it. [1]: https://issues.dlang.org/show_bug.cgi?id=1807 |
May 07, 2018 Re: sumtype 0.3.0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | On Sunday, 6 May 2018 at 19:18:02 UTC, Paul Backus wrote:
> SumType is a generic sum type for modern D. It is meant as an alternative to `std.variant.Algebraic`.
>
> Features:
> - Pattern matching, including support for structural matching (*)
> - Self-referential types, using `This`
> - Works with `pure`, `@safe`, `@nogc`, and `immutable` (*)
> - Zero runtime overhead compared to hand-written C
> - No heap allocation
> - Does not rely on runtime type information (`TypeInfo`) (*)
>
> Starred features (*) are those that are missing from `Algebraic`.
>
> Code examples are available in the documentation (linked below).
>
> New in this release:
> - The list of types allowed in a sum type is now public
> - Implicit qualifier conversions are now allowed in pattern matching
> - Better code examples in the documentation
>
> This library is a work in progress. If you have a use case you'd like to see supported, or an API you'd like to see implemented, please get in touch!
>
> Documentation: https://pbackus.github.io/sumtype/sumtype.html
> DUB: https://code.dlang.org/packages/sumtype
> Github: https://github.com/pbackus/sumtype
Yeeeees.
I love it when someone else goes and implements something that was on my TODO stack. Dmitry Olshansky did it last week with Photon, then you come along and take another item from me as well. Less work for me!
Good work, definitely going to try this out.
|
May 07, 2018 Re: sumtype 0.3.0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | Another similar project: http://taggedalgebraic.dub.pm/ |
May 07, 2018 Re: sumtype 0.3.0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sönke Ludwig | On 07.05.2018 22:28, Sönke Ludwig wrote:
> Another similar project: http://taggedalgebraic.dub.pm/
And it's pretty nice one. I use it for couple of years.
|
May 07, 2018 Re: sumtype 0.3.0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sönke Ludwig | On Monday, 7 May 2018 at 19:28:16 UTC, Sönke Ludwig wrote:
> Another similar project: http://taggedalgebraic.dub.pm/
There's also tagged_union and minivariant on dub, that I've found. I'm definitely far from the first person to be dissatisfied with `Algebraic`, or to try my hand at writing a replacement.
The main difference between all of those and sumtype is that sumtype has pattern matching. Personally, I consider that an essential feature--arguably *the* essential feature--which is why I went ahead with Yet Another implementation anyway.
|
May 08, 2018 Re: sumtype 0.3.0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | On Sunday, 6 May 2018 at 19:18:02 UTC, Paul Backus wrote:
> snip
Wow.. without comments and unittests, the implementation is only 116 lines. Awesome job. Even now I still find it incredible what D can do. Is Algebraic in the standard library really that bad? And if so, why aren't implementations like this being accepted?
|
Copyright © 1999-2021 by the D Language Foundation