hyogwa icon indicating copy to clipboard operation
hyogwa copied to clipboard

Simpler effect representations creation

Open ENvironmentSet opened this issue 2 years ago • 2 comments

currently, effect representations are created like following:

interface IO extends Spec<'IO'> {
  read(): string
  write(text: string): void
}
const IO = createEffect<IO>('IO')

Here, name of effect is repeated 5 times. this makes look of API verbose and makes users be tired of writing name of effects. Using interface, adding discrimination tag to spec type, having effect representation in variable, mentioning name of spec when creating effect representation seems to be inevitable. But giving name of effect we want to create as string literal seems to be avoidable and I really hope so. let's find a way.

ENvironmentSet avatar Aug 07 '23 14:08 ENvironmentSet

Here, I share my failed try. I tried to use symbols to dynamically -- and the way user don't notice -- generate identifier of effect representation but found this kind of work would make handler API verbose.

ENvironmentSet avatar Aug 07 '23 15:08 ENvironmentSet

Update: now we define effects like blow

type IO = Effect<'IO', {
  read(): string
  write(text: string): void
}>
const IO = createPrimitives<IO>('IO')

It's better but still have annoying repeat of effect name

ENvironmentSet avatar Aug 28 '23 01:08 ENvironmentSet