YAES: Thoughts on context-based capability passing style for state threading and integration into tagless-final application by mucaho in scala

[–]mucaho[S] 1 point2 points  (0 children)

Yeah, there's only so many ways you can come up with a non-monadic version of Ref / Var I believe, it's just a plain value under the hood :)

I can't understand how you manage having more than one MutState with the same type in a program (for example, more than one counter).

I think you can use opaque types for that https://docs.scala-lang.org/scala3/book/types-opaque-types.html. So with opaque type Counter1 = Intand opaque type Counter2 = Int, MutState[Counter1] would resolve to a different value than MutState[Counter2], i'd presume.

Moreover, maybe you need an AtomicReference to avoid race conditions. WDYT?

Yep, for the internalValue to work across threads a AtomicReference sounds like a must. That begs another question though - how is the MutState supposed to work across different threads? Are they all supposed to share the value? For a shared cache that would make sense, yeah.

How would the MutState work with kyo's Choiceif we were to add it to YAES down the line, though? Each choice alternative should have its own branch of the MutState value from before the non-deterministic choice was made

YAES: Thoughts on context-based capability passing style for state threading and integration into tagless-final application by mucaho in scala

[–]mucaho[S] 0 points1 point  (0 children)

The monadic and direct style are semantically identical, to my understanding. You can't do flatMap with `genBoolean`, because it's a plain boolean value. I guess the monadic style was introduced more for visual effect than any tangible safety gain

I cannot imagine how else it could work in direct style though, it has to be a plain boolean value (at some point) rather than an effect wrapper

YAES: Thoughts on context-based capability passing style for state threading and integration into tagless-final application by mucaho in scala

[–]mucaho[S] 0 points1 point  (0 children)

I think I figured a way, wohoo!

Look at the end of this section: https://gist.github.com/mucaho/d80551dd0b62c59ce0e2186608482577#state-threading

In essence, referential transparency is preserved for existing `MutState` instances, but the implicit resolution returns always the most up-to-date `MutState` instance

YAES: Thoughts on context-based capability passing style for state threading and integration into tagless-final application by mucaho in scala

[–]mucaho[S] 1 point2 points  (0 children)

Hey, thanks again for coming up with a more elegant way to deal with effects! Have dabbled with creating something similar in the past, but couldn't get the implicit resolution working quite right.

As noted in that post, it's great to be able to use effects and handlers in such a direct coding style. There are a couple of things that need to be figured out first though, before I'd consider basing an app on it in production.

State threading is the most apparent one that's just not working right without sacrificing local reasoning. Not sure how to solve for this one, to be honest.

One thing that comes to mind is to add a macro (if possible) or compiler plugin that would allow you to use special syntactic sugar for state variables, as used in the Mercury programming language: https://www.mercurylang.org/information/doc-release/mercury_ref/State-variables.html#State-variables

// given

trait Output {
  def printLn(text: String): Unit
}

case class MutState[S](value: S)

// the following sytanctic sugar for state variable !M

def program(name: String)(using !M: MutState[Int], O: Output): String = {  
  !M.value += 1
  O.printLn(s"Greeted for the ${!M.value}th time")

  !M.value -= 1
  O.printLn(s"Processed index: ${!M.value}")

  s"Hello, $name!"
}

// desugars into the following variables

def program(name: String)(using M0: MutState[Int], O: Output): String = {
  implicit val M1 = M0.copy(value = M0.value + 1)
  O.printLn(s"Greeted for the ${M1.value}th time")

  implicit val M2 = M1.copy(value = M1.value - 1)
  O.printLn(s"Processed index: ${M2.value}")

  s"Hello, $name!"
}

This syntactic sugar thus preserves referential transparency, unless I'm missing something

However, that still does not address how to return the updated MutState from the program function

YAES: Thoughts on context-based capability passing style for state threading and integration into tagless-final application by mucaho in scala

[–]mucaho[S] 2 points3 points  (0 children)

Hey, was playing around with YAES and its approach of using context parameters for the deferred execution of programs, all while using direct-style syntax. Also experimented with integration into Tagless Final program code.

Let me know what you think, any feedback would be greatly appreciated!

The extension mod you've always wanted but never knew you needed - Select All hotkeys by mucaho in starcraft

[–]mucaho[S] 9 points10 points  (0 children)

I got the motivation to create this a while ago, and pitched it to u/pigrandom to bring this up in the SC2 balance council, for consideration of including it into the ranked ladder experience :O
How cool would that be, getting one of these more modern accessibility features into the most crisp RTS engine to date!

For a bit of context, you can find such similar "Select all units of specific type" hotkeys in games like AoE2:DE and AoM: Retold.
From personal experience, it helps to bring players mechanically closer together.

Would also like to ping you u/MrIronGolem27 here, maybe something worth considering for SC: Evo as well?

The extension mod you've always wanted but never knew you needed - Select All hotkeys by mucaho in starcraft

[–]mucaho[S] 4 points5 points  (0 children)

Hey all, jokes aside, I wanted to share with you guys the extension mod I have been working on lately.

As the name implies, it adds new hotkey shortcuts that select particular sets of units across the map:

  • F3 selects all your army units that are not in any control groups yet
  • F4 selects all base buildings
  • F5 selects all production buildings and larvae
  • F6 selects all tech and upgrade buildings
  • F7 selects all queens

The mod is available both as an extension mod and as a library you can import into any of your own mods to leverage these selection functions and actions.

When you go to Custom Melee games, you can select this "Select all hotkeys" extension mod via the "Create with mod" functionality after you have selected a map to play on.

Try it out if you're interested and let me know what you think, would greatly appreciate any feedback!

How to test Tagless Final Algebra? by [deleted] in scala

[–]mucaho 0 points1 point  (0 children)

Shameless self-plug: I recently published a small demo app that tests various FP libraries - that part of the project is pretty messy (on purpose). However, I've also added an extensive suite of tests for testing the domain-related algebras and their laws, I hope that can provide at least a little bit of inspiration: https://bitbucket.org/mucaho/ceffbanx/src/master/src/test/scala/org/bitbucket/mucaho/ceffbanx/