Some examples related to my tweet rant https://twitter.com/dsymetweets/status/1294276915260522496
In project programming this hit me this week with a bug:
| namespace PhantomTypes | |
| module Phantom = | |
| // Private, so must use function 'prove'. | |
| type ProofOf<'a> = private | ProofOfA | |
| // A module proves that it can construct values of type 'a' by providing a value to this function. | |
| let prove (_ : 'a) : ProofOf<'a> = ProofOfA |
| module GADTMotivation | |
| (* | |
| Here is a simple motivational example for GADTs and their usefulness for library design and domain modeling. Suppose we | |
| need to work with settings which can be displayed and adjusted in a GUI. The set of possible setting "types" is fixed | |
| and known in advance: integers, strings and booleans (check-boxes). | |
| The GUI should show an example value for each possible setting type, e.g. 1337 for an integer setting and "Hello" for a | |
| string setting. How can we model this small domain of setting types and computing example values? | |
| *) |
Some examples related to my tweet rant https://twitter.com/dsymetweets/status/1294276915260522496
In project programming this hit me this week with a bug:
| // ========= Event Sourcing in a nutshell | |
| (* | |
| FriendlyName: string | |
| Aggregate friendly name. | |
| Initial: 'State | |
| Initial (empty) state we will start with. | |
| Decide: 'Command -> 'State -> 'Event list |
| module DragDropPage | |
| open Feliz | |
| open Fable.React | |
| open Fable.React.Props | |
| open ReactDND | |
| type Language = { | |
| Name: string | |
| } |
| using System; | |
| using System.Collections.Generic; | |
| using System.Configuration; | |
| using System.IO; | |
| using System.Text; | |
| using System.Threading; | |
| using System.Xml; | |
| using System.Xml.Serialization; | |
| using System.Linq; | |
| using domain; |
| HANGMANPICS = [''' | |
| +---+ | |
| | | | |
| | | |
| | | |
| | | |
| | | |
| =========''', ''' | |
| +---+ |
| [ | |
| { | |
| "name": "Afghanistan", | |
| "dial_code": "+93", | |
| "code": "AF" | |
| }, | |
| { | |
| "name": "Aland Islands", | |
| "dial_code": "+358", | |
| "code": "AX" |
| open System | |
| open System.IO | |
| type State<'s, 'a> = State of ('s -> ('a * 's)) | |
| module State = | |
| let inline run state x = let (State(f)) = x in f state | |
| let get = State(fun s -> s, s) | |
| let put newState = State(fun _ -> (), newState) | |
| let map f s = State(fun (state: 's) -> |