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
namespace FSharpTests | |
module Analytics = | |
open System | |
let getData (skuId: int) = | |
// fake data for now: | |
// a list of (date, value) observations | |
[ DateTime(2010, 1, 1), 10.; |
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 | |
// Sample with replacement | |
let replaceSampler (rng: Random) (counts: int[]) = | |
let N = counts |> Array.sum | |
let draw = rng.Next(N) | |
let rec find index cumul = | |
let n = counts.[index] | |
if draw < (cumul + n) | |
then index |
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 | |
open System.IO | |
let path = @"C:\Users\Mathias\Desktop\Dojo\DigitsSample.csv" | |
let data = File.ReadAllLines(path) | |
let parsed = data |> Array.map (fun line -> line.Split(',')) | |
let parsed2 = parsed.[1..] |> Array.map (fun line -> line |> Array.map (fun x -> Convert.ToInt32(x))) | |
type Example = { Number:int; Pixels:int[] } | |
let sample = parsed2 |> Array.map (fun x -> { Number = x.[0]; Pixels = x.[1..] }) |
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
#I @"C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\3.0\Runtime\v4.0\Type Providers" | |
open System | |
#r "System.ServiceModel.dll" | |
open Microsoft.FSharp.Linq | |
#r "FSharp.Data.TypeProviders" | |
type terraService = Microsoft.FSharp.Data.TypeProviders.WsdlService<"http://terraserver-usa.com/TerraService2.asmx?WSDL"> | |
let terraClient = terraService.GetTerraServiceSoap () |
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 City = { Name: string; Lat: float; Lng: float } | |
let cities = | |
[ ("San Francisco", "CA", "United States"); | |
("New York", "NY", "United States"); | |
("Hoboken", "NJ", "United States"); | |
("Redmond", "WA", "United States"); | |
("Seattle", "WA", "United States"); | |
("Boston", "MA", "United States"); | |
("Boston", "MA", "United States"); |
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
#r "office.dll" | |
#r "Microsoft.Office.Interop.Excel" | |
open Microsoft.Office.Interop.Excel | |
open System.Runtime.InteropServices | |
let xl = Marshal.GetActiveObject("Excel.Application") :?> Microsoft.Office.Interop.Excel.Application | |
let wbs = xl.Workbooks | |
let wb = wbs.[1] | |
let sh = wb.Worksheets.[1] :?> Worksheet | |
sh.Cells.[1,1] <- "Hello from F#!" |
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
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 |