Skip to content

Instantly share code, notes, and snippets.

@Swoorup
Last active February 2, 2021 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Swoorup/3d75a8cd5479270fae96aa4ce33f0fde to your computer and use it in GitHub Desktop.
Save Swoorup/3d75a8cd5479270fae96aa4ce33f0fde to your computer and use it in GitHub Desktop.
Testing Anonymous typed-tagged unions.
open System;;
let random = new Random();
let _rollTheDice (): (int|string) =
let number = random.Next(1, 6)
if (number >= 2) then number else "Winner"
let cls () = System.Console.Clear();;
type A = (int|string|int64)
let sth(): A = 1
let consumeSubset(b: (int64|string)) = ..
let consume() =
match sth() with
| :? int as i -> ..
| lOrStr -> /// inferred as (int64|string)
consumeSubset(lOrStr)
type Operand = byte[]
type Ref = byte[]
type AddInst = AddInst of Operand * Operand
type MulInst = MulInst of Operand * Operand
type SubInst = SubInst of Operand * Operand
type LoadInst = LoadInst of Ref * Ref
type SaveInst = SaveInst of Ref * Ref
type Noop = Noop of unit
type ArithInst = (AddInst | MulInst | SubInst)
type MemOps = (LoadInst | SaveInst)
type ArithmeticProcessor = ArithOps -> unit
type MemoryProcessor = MemOps -> unit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment