top | item 39854071

(no title)

ethangk | 1 year ago

This reminds me of the Make Illegal States Unrepresentable[0] idea, where something will return a ‘ResolvedExecutor’ type to guarantee that you’re only working with something in the state you want. Go makes this a little clunky to do, though. I suppose you could use Generics to implement a Preresolved and Resolved struct.

[0] https://fsharpforfunandprofit.com/posts/designing-with-types...

discuss

order

iainmerrick|1 year ago

You start with a Resolver, call Resolver.Execute, and up with a Resolved (which happens to be the same object, but that's really an implementation detail). But the type system doesn't prevent you making further calls to Resolver -- that's one of the illegal uses we'd like to prevent, if I understand the example.

It might work in a language with linear types or some concept of ownership. Execute() would take ownership of the Resolver and prevent it being called again.