tic-tac-toe-backend icon indicating copy to clipboard operation
tic-tac-toe-backend copied to clipboard

Use F#+

Open gusty opened this issue 2 years ago • 4 comments

Hi @battermann

At the time you did this interesting experiment, F#+ didn't support Free Monads, but now it does and I tried to use it to generalize the patterns, together with Coproduct to compose the different sets of instructions.

As you can see, although F# doesn't support HKTs / typeclasses, you can still go a bit further with F#+ "magic", based on advanced SRTP techniques.

In addition to the above mentioned, I did also some other changes:

  • Replaced Suave and Chessie with pure F#+ code, using Monad Transformers.
  • Removed completely paket in favor of #r "nuget: ..." feature which wasn't present at the moment you wrote this code.
  • Fixes some errors, at least running it with windows and VS it didn't work, I had hack a bit paths.

@wallymathieu did also some fixes

Last but not least, I have a question for you. You said in the blog that:

Due to missing type classes it is not possible to compose existing programs together without any hard dependencies.

If we wanted to make the application layer of the Tic-Tac-Toe backend more pure by implementing the free monad pattern there as well,

I'm very curious about how would you implement it there, forget the composition problem, as I think F#+ can solve it, let's pretend you don't have any limitation, can you tell me a but how it would look like ? Maybe we can give it a try.

gusty avatar Feb 20 '23 06:02 gusty

Hi,

this looks amazing :) Unfortunately, I haven't worked with F# for years, and even though I would love to, I currently I don't have the capacities to pick it up again. I can make you a collaborator, if you like, unless you prefer working with your fork?

battermann avatar Feb 23 '23 10:02 battermann

Sure, I will be happy become a collaborator.

Anyways, my question wasn't specific to F# but more conceptually. Right now, what I see is that you use the Free Monad only for the "infrastructure" part of your code, except the application layer.

The logic is just normal functions. So my question is what was your end goal that lack of HKTs/typclasses prevented you from achieving.

If you don't work with F# anymore, even better, maybe you can tell me in Haskell terms how would you improve your solution.

gusty avatar Feb 23 '23 16:02 gusty

Sure, I will be happy become a collaborator.

Anyways, my question wasn't specific to F# but more conceptually. Right now, what I see is that you use the Free Monad only for the "infrastructure" part of your code, except the application layer.

The logic is just normal functions. So my question is what was your end goal that lack of HKTs/typclasses prevented you from achieving.

If you don't work with F# anymore, even better, maybe you can tell me in Haskell terms how would you improve your solution.

Since this is from 7 years ago, I cannot 100% recall what I had in mind back then :)

What I would do e.g. in Scala which is also not a purely functional language is to push all the side effects to the boundary of the application (aka "the end or the world").

This way you can e.g. test your program using "fake" in memory interpreters. And if e.g. the effect type of the application is abstract, you can use the Id or State monad for your test interpreters.

In Scala, this can be achieved by using the tagless final pattern or ZIO.

In Haskell, I would use an effect system library like Polysemy e.g. or just monad transformers or MTL.

battermann avatar Feb 24 '23 08:02 battermann

Thanks. I was hoping something more along the lines described here which btw, it's Scala but I don't see any "building block" not present in F#+.

gusty avatar Feb 24 '23 09:02 gusty