nessos / Eff

A library design for programming with effects and handlers in C#
MIT License
128 stars 13 forks source link

Question about the example EffectHandler in README.md #3

Closed jpierson closed 5 years ago

jpierson commented 6 years ago

What is the purpose of returning the type ValueTask from Handle in the main example from README.md. Additionally this method is async but doesn't await anything awaitable, is this intentional as it seems that the async keyword could just be omitted in the example?

palladin commented 6 years ago

Actually, the correct type of Handle is Handle<T> : IEffect<T> -> Task and the reason is that we need to compose it with Run Run<T> : Eff<T> -> IEffectHandler -> Task<T> Of course we can define our own Run and Handlers.

jpierson commented 6 years ago

I tried getting the example in the Readme.md file working in LinqPad to play around with more to see if I could make sense out of your explanation above but unfortunately I'm hitting the following error.

CS0117 'Effect' does not contain a definition for 'Random'

http://share.linqpad.net/qrh376.linq

Glancing through the source code I haven't spotted a method called Random on Effect that would allow this example to compile as is. My guess is that I'm overlooking something.

palladin commented 6 years ago

The example is not complete, is only for demonstration purposes.

solvingj commented 6 years ago

Note that the RandomEffect in the readme example comes from the following example project in the solution.

https://github.com/nessos/Eff/blob/0233d59dd3ca9f62050096dc77224e5f804f1261/src/examples/Eff.Examples.RecordReplay/RecordEffectHandler.cs

I believe RandomEffect is an example of a user-defined Effect. Is that correct @palladin ?

palladin commented 6 years ago

Yes!