Skip to content

Instantly share code, notes, and snippets.

@halcwb
halcwb / RiderScriptCrash.fsx
Created August 31, 2026 05:43
Rider crashes
// ═══════════════════════════════════════════════════════════════════════════════
// GenPRES – MainEHR Integration: the system model, executable
// ═══════════════════════════════════════════════════════════════════════════════
//
// dotnet fsi Session.fsx
//
// Standalone — no #load, no #r. It prints a trace per scenario and ends with a count
// of self-checks.
//
// ═══════════════════════════════════════════════════════════════════════════════
@halcwb
halcwb / .editorconfig
Created August 19, 2026 10:20
Editor config settings for use of Fantomas in GenPRES
root = true
[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
# Final newlines are necessary for a lot of unix tools to work as expected. See
# https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline for more info.
insert_final_newline = true
@halcwb
halcwb / Session.fsx
Last active August 23, 2026 18:19
Modelling main EHR - GenPRES - User session management
// ═══════════════════════════════════════════════════════════════════════════════
// GenPRES – MainEHR Integration: the system model, executable
// ═══════════════════════════════════════════════════════════════════════════════
//
// A runnable model of the design document *GenPRES – MainEHR Integration*. The
// document is leading: every type, message and branch below exists to carry one of
// its Actors, Concepts, Constraints or Rules, and cites it by number. Nothing the
// document does not sanction lives here.
//
// The file is standalone — no #load, no #r. Run it with:
@halcwb
halcwb / PersonExample.fsx
Created May 27, 2026 14:28
An example of using type and module
// declare the type outside the module
type Person = {First:string; Last:string}
module Functional =
let invert f x y = f y x
let invert2 f = fun x y -> f y x
@halcwb
halcwb / FunctionalProgrammingDesing.md
Last active May 26, 2026 11:03
A skill definition for functional programming design

Functional Programming Design

A reference for applying design patterns in functional programming. F# is used throughout, but the ideas transfer to any ML-family language.

Core Principles

  • Functions are things — values that can be passed, returned, stored.
  • Functions compose — small functions glue into larger ones at type seams.
  • Types are not classes — no inheritance, no methods, no hidden state.
  • Types compose — products and sums build all data.
@halcwb
halcwb / claude.fsx
Created May 25, 2026 10:11
Showing how original Claude code should be improved
open System
// Literal Claude code implementation
module Impl1 =
// ── Default Model Resolution ──┈┈┈┈┈┈┈┈┈┈┈┈┈
/// Returns the canonical name for a model string (strips date/provider suffixes)
@halcwb
halcwb / M.fsx
Created May 17, 2026 10:22
Learning the Monad
// ============================================================================
// M.fsx — the Identity monad, and the Functor / Applicative / Monad it
// generates.
// ----------------------------------------------------------------------------
// WHY THIS SETUP
//
// `M<'T>` is the simplest possible monad: a box that merely holds a value
// (`M of 'T`) with no extra effect. That makes it the ideal *skeleton* for
// studying the abstraction itself — nothing distracts from the structure.
//
@halcwb
halcwb / fsHarness.fsx
Created May 16, 2026 06:37
FSharp Harness
// coding-agent.fsx
// Claude-Code-like harness in F#. Two modes from one script:
// default -> in-process REPL agent driven by a local Ollama model via Microsoft.Extensions.AI
// "mcp" arg -> MCP server over stdio exposing the same three tools
//
// Run agent mode: dotnet fsi coding-agent.fsx
// (optional: OLLAMA_HOST, OLLAMA_MODEL)
// Run MCP mode: dotnet fsi coding-agent.fsx mcp
//
// Requires a running Ollama instance with a tool-calling-capable model pulled, e.g.
#!/usr/bin/dotnet fsi
open System
open System.Collections.Generic
open System.Globalization
open System.IO
open System.Net.Http
open System.Numerics
open System.Text
@halcwb
halcwb / Agent.fsx
Last active August 14, 2025 12:48
A more safe and functional approach to create and use MailboxProcessor as Agent
open System
open System.Threading
open System.Threading.Tasks
/// <summary>
/// Represents an asynchronous agent that processes messages of type 'T.
/// This is a wrapper around FSharp's MailboxProcessor, providing a unified API for agent-based concurrency.
/// </summary>
type Agent<'T>(body: Agent<'T> -> Async<unit>) as self =