↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

Making program behaviour explicit | Pirrmann's train of thought

The post shows F# computation expressions being used to capture an expression, mutate it, and then evaluate the altered result. The examples are built to produce unpredictable runtime behavior, with mutations that can cause subtle bugs and difficult debugging.

It also sketches a builder that quotes an expression in Run, passes it through a mutation step, and evaluates the result. The author notes that the same approach can be used for mutation testing, and closes by saying that computation expressions remain a powerful way to build DSLs.

Reading notes
#

  • Computation expressions are presented as a way to make runtime behavior unpredictable by mutating quoted expressions before evaluation.
  • The examples use custom syntax such as usually, mostProbably, and pray to show how mutations can change results.
  • The text describes different states for the mutation process, including a default chance of mutation, a safe state, and an angry state with more mutations.
  • The implementation sketch centers on a ChaosBuilder with Return, Quote, and Run, where Run mutates the quoted expression and evaluates it.
  • An IMutationSitePicker chooses where to mutate, and an IExpressionReplacer performs the replacement.
  • A sample MutateWithProbability implementation uses System.Random and a mutable last-random value to decide whether to pick the next site.
  • The author says the actual expression manipulation code is not included, but the current work is available as a Gist.
  • The post connects the idea to mutation testing and mentions numeric constant mutation, operator replacement, reordering pattern matching, and type-aware function replacement.
  • The conclusion says computation expressions are a powerful F# feature and can be used to write DSLs.