Type-safe channels (Re: One year of Go)
Sean Kelly
sean at invisibleduck.org
Sun Nov 21 07:21:28 PST 2010
Graham Fawcett <fawcett at uwindsor.ca> wrote:
> Hi Sean,
>
> On Tue, 16 Nov 2010 10:45:37 -0500, Sean Kelly wrote:
>
>> Graham Fawcett Wrote:
>>
>>> On Fri, 12 Nov 2010 18:15:15 -0500, Sean Kelly wrote:
>>>>
>>>> To be honest, I haven't spent much time with Go because my
>>>> cursory exposure to the language hasn't shown it to solve the
>>>> problems I care about better than the languages I currently use.
>>>> I think Go is in the right ballpark with channels though, and the
>>>> rest is passable. I'm trying to withhold my opinion about the
>>>> lack of generics and such and evaluate the language based on
>>>> what's there.
>>>
>>> Since you brought up channels...
>>>
>>> One thing I very much like about Go (and Haskell, etc.) that I
>>> don't think has a counterpart in Phobos is type-safe message
>>> passing. I like the flexibility of the current "mailbox" design.
>>> But I'd really like an alternative that could enforce type-safety
>>> on messages. I don't think per-thread mailboxes could accommodate
>>> this, but Channel objects could; e.g.:
>>>
>>> struct Channel(T) {
>>> T receive() { ... }
>>> void send(T val) { ... }
>>> }
>>
>> It shouldn't be too difficult to wrap send/receive with such a
>> design to provide type safety. In fact, it's one reason I wanted to
>> use the flexible model. Of course, using channels would be a matter
>> of convention, since both would be available.
>
> I don't have code at hand, but I remember getting frustrated trying to
> put a type-safe wrapper around send/receive. I think the compiler was
> failing to correctly type-check the delegates I was using to process
> the messages against the types of messages I was trying to enforce.
> But I was probably just doing it wrong, I'm still a D newbie.
That's a compiler bug. spawn has the same problem.
More information about the Digitalmars-d
mailing list