This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Program () = | |
let f (x:float) = 2.0 * x + 1.0 | |
member this.Run (x:float) = | |
let result = f x | |
printfn "Result: %.2f" result | |
let program = Program() | |
program.Run(10.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def suits [:spade :club :diamond :heart]) | |
(def ranks [2 3 4 5 6 7 8 9 10 :jack :queen :king :ace]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
'Of Turtles & Discriminated Unions' | |
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
The goal of this exercise is to introduce F# discriminated | |
unions, and how they can be used to design a DSL. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
This is a reaction to this blog post by Steve Shogren: | |
http://deliberate-software.com/safety-rank-part-2/ | |
*) | |
#I @"../packages" | |
#r @"Accord.3.0.1-alpha\lib\net45\Accord.dll" | |
#r @"Accord.MachineLearning.3.0.1-alpha\lib\net45\Accord.MachineLearning.dll" | |
#r @"Accord.Math.3.0.1-alpha\lib\net45\Accord.Math.dll" | |
#r @"Accord.Statistics.3.0.1-alpha\lib\net45\Accord.Statistics.dll" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
let readInt () = Console.In.ReadLine() |> int | |
let N = readInt () | |
let readline = [ for i in 0 .. N - 1 -> readInt () ] | |
let minimumBetweenTwoNumbers n1 n2 = min n1 n2 | |
let rec minimum data mini = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rec minimum data mini = | |
match data with | |
| first::second::tail -> | |
let min = abs (first - second) |> minimumBetweenTwoNumbers mini | |
match tail with | |
| [] -> min | |
| _ -> minimum second::tail min |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a conversion to F# of the C# code presented in | |
// MSDN Magazine, March 2015, by James McCaffrey: | |
// https://msdn.microsoft.com/en-us/magazine/dn913188.aspx | |
open System | |
let sumprod (v1:float[]) (v2:float[]) = | |
Seq.zip v1 v2 |> Seq.sumBy (fun (x,y) -> x * y) | |
let sigmoid z = 1.0 / (1.0 + exp (- z)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// just a tiny tweak on the Fractal Forest dojo: | |
// https://github.com/c4fsharp/Dojo-Fractal-Forest | |
open System | |
open System.Drawing | |
open System.Windows.Forms | |
let width, height = 500, 500 | |
let form = new Form(Width = width, Height = height) | |
let box = new PictureBox(BackColor = Color.White, Dock = DockStyle.Fill) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Uses Accord.NET version 2.14.0 | |
#r @"..\packages\Accord.2.14.0\lib\net40\Accord.dll" | |
#r @"..\packages\Accord.Math.2.14.0\lib\net40\Accord.Math.dll" | |
#r @"..\packages\Accord.Statistics.2.14.0\lib\net40\Accord.Statistics.dll" | |
#r @"..\packages\Accord.MachineLearning.2.14.0\lib\net40\Accord.MachineLearning.dll" | |
open System | |
open System.IO | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// blog post: http://clear-lines.com/blog/post/Fun-with-L-system.aspx | |
type Symbol = | Sym of char | |
type State = Symbol list | |
type Rules = Map<Symbol,State> | |
type LSystem = | |
{ Axiom:State |