Skip to content

Instantly share code, notes, and snippets.

//===================================
// Example of using DataTables in F#
//===================================
open System
open System.Data
//===================================
// General DataTable helpers
//
@swlaschin
swlaschin / Calculator_implementation.fsx
Last active July 30, 2023 14:50
Type-first design and implementation for a calculator app
(*
Calculator_implementation.fsx
Related blog post: http://fsharpforfunandprofit.com/posts/calculator-implementation/
*)
// ================================================
// Draft of Domain from previous file
// ================================================
module CalculatorDomain_V3 =
@swlaschin
swlaschin / AgeProperties.fsx
Last active September 13, 2021 07:54
FsCheck properties to use to check a "how many years old" function
module PropertiesForDob =
let badAge (today:System.DateTime) (dob:System.DateTime) =
let dob = dob.Date // ignore time
let today = today.Date // ignore time
let ts = today.Subtract(dob)
ts.Days / 365 // bad implementation
let goodAge (today:System.DateTime) (dob:System.DateTime) =
namespace AwesomeAngularMVCApp.Controllers
open System.Threading.Tasks
open System.Web
open System.Web.Mvc
open AwesomeAngularMVCApp.Models
open Microsoft.AspNet.Identity.Owin
open System.Web.Http.Owin
[<Authorize>]
(*
CapabilityBasedSecurity_ConfigExample.fsx
An example of a simple capability-based design.
Related blog post: http://fsharpforfunandprofit.com/posts/capability-based-security/
*)
/// Configuration system
module Config =
@swlaschin
swlaschin / enterprise-tic-tac-toe.fsx
Last active June 5, 2023 22:10
An example of implementing "enterprise" tic-tac-toe in a functional way. Related blog post: http://fsharpforfunandprofit.com/posts/enterprise-tic-tac-toe/
(*
enterprise-tic-tac-toe.fsx
An example of implementing "enterprise" tic-tac-toe in a functional way.
Related blog post: http://fsharpforfunandprofit.com/posts/enterprise-tic-tac-toe/
*)
open System
@swlaschin
swlaschin / enterprise-tic-tac-toe-2.fsx
Last active June 5, 2023 22:16
Follow up to the example of implementing "enterprise" tic-tac-toe in a functional way.
(*
enterprise-tic-tac-toe-2.fsx
Follow up to the example of implementing "enterprise" tic-tac-toe in a functional way.
* Added true capability based security.
Related blog post: http://fsharpforfunandprofit.com/posts/enterprise-tic-tac-toe-2/
*)
@swlaschin
swlaschin / 1-ConciseDDD.fsx
Created March 24, 2015 21:57
Code from O'Reilly webcast: "Domain Modelling with the F# Type System" http://www.oreilly.com/pub/e/3340
// ================================================
// DDD : Model a card game
// ================================================
(*
A card is a combination of a Suit (Heart, Spade) and a Rank (Two, Three, ... King, Ace)
A hand is a list of cards
A deck is a list of cards
A player has a name and a hand
A game consists of a deck and list of players
@swlaschin
swlaschin / ConstrainedTypesExamples.fsx
Last active March 1, 2024 18:19
Examples of creating constrained types in F#
// General hints on defining types with constraints or invariants
//
// Just as in C#, use a private constructor
// and expose "factory" methods that enforce the constraints
//
// In F#, only classes can have private constructors with public members.
//
// If you want to use the record and DU types, the whole type becomes
// private, which means that you also need to provide:
// * a constructor function ("create").