F# typed environment config with validation
F#
open System
type Config = { Host: string; Port: int; Debug: bool }
let loadConfig () =
let get key fallback =
match Environment.GetEnvironmentVariable key with
| null | "" -> fallback
| value -> value
let port =
match Int32.TryParse(get "APP_PORT" "8080") with
| true, p when p > 0 && p < 65536 -> p
| _ -> failwith "APP_PORT must be an integer between 1 and 65535"
{ Host = get "APP_HOST" "127.0.0.1"
Port = port
Debug = (get "APP_DEBUG" "false").ToLowerInvariant() = "true" }