Skip to content

Simplify vars and envs#474

Merged
AlexeyRaga merged 1 commit into
masterfrom
remove-env
Dec 24, 2025
Merged

Simplify vars and envs#474
AlexeyRaga merged 1 commit into
masterfrom
remove-env

Conversation

@AlexeyRaga
Copy link
Copy Markdown
Contributor

Simplifying Vars and Envs

Instead of storing values in Env, Vars now store concrete values:

type Var<'T> =
    internal
    | Symbolic of 'T option
    | Concrete of 'T

This allows simplifying Var itself, but also removes the need of reflective state traversal for reporting the state.

Justification

In .NET we don't have HKT, so we don't HTraverse between symbolic and concrete state anyway. Instead, state always holds Var<'T>, so there is no need in runtime correlation between Env and Var.

This means that during execution stage we can simply create a concrete Var (with value) and pass it to Update.
Update will still not be able to distinguish between symbolic and concrete variables, as expected.

Env is still being received by execution-stage methods (Require, Execute, Ensure) and is still required by Var.Resolve because it serves the role of the capability and provides some compile-time safety: if you don't have Env you can't have access to concrete state.

Results

With this approach we:

  • Have much simple Var (win for maintenance)
  • Can print state naturally (win for devex debugging)
  • Don't need heavy reflection traversal of state in order to print in into the report (win from any angle)
  • Have less code lines :)

Report example

image

@AlexeyRaga AlexeyRaga merged commit f216518 into master Dec 24, 2025
2 checks passed
@AlexeyRaga AlexeyRaga deleted the remove-env branch December 24, 2025 02:56
Copy link
Copy Markdown
Member

@moodmosaic moodmosaic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking forward porting my hello-world example into Hedgehog.Stateful 👀 🥳

@AlexeyRaga
Copy link
Copy Markdown
Contributor Author

@moodmosaic
Copy link
Copy Markdown
Member

What Resolve means in oldState.CurrentCount.Resolve(env)?

@AlexeyRaga
Copy link
Copy Markdown
Contributor Author

Resolve is the way to obtain Var's value.
In particular, oldState.CurrentCount.Resolve(env) means "give me the value from the old (before update) state".

@moodmosaic
Copy link
Copy Markdown
Member

Do you have a use case for it?

@AlexeyRaga
Copy link
Copy Markdown
Contributor Author

Anything to assess that the state has changed in an expected way (or not changed).
For example, if you want to assert that the counter has been incremented by an expected value (from the input).
Or that if, when you change the door lock code, the door remains locked...

Similarly how Haskell version defines.

Ensure (state Concrete -> state Concrete -> input Concrete -> output -> Test ())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants