Skip to content

Instantly share code, notes, and snippets.

View bjartwolf's full-sized avatar

Bjørn Einar Bjartnes bjartwolf

View GitHub Profile
@bjartwolf
bjartwolf / 1a.fs
Last active August 29, 2015 13:59
streetfight1a
[<Measure>] type Length
[<Measure>] type Area = Length*Length
let area (b : float<Length>) (a: float<Length>) = a*b^2
let a1:float<Area> = area 3.0<Length> 5.0<Length>
@bjartwolf
bjartwolf / 1b.fs
Created April 11, 2014 22:20
1b.fs
[<Measure>] type Length
[<Measure>] type Area = Length*Length
let area (a : float<Length>) (b: float<Length>) = a * a + b * b
let a1:float<Area> = area 0.0<Length> 1.0<Length>
a1.Dump()
[<Measure>] type Length
[<Measure>] type Area = Length*Length
let area (a : float<Length>) (b: float<Length>) = a * a *a / b
let a1:float<Area> = area 0.0<Length> 1.0<Length>
let a2:float<Area> = area 1.0<Length> 0.0<Length>
("for 0,1: " + a1.ToString()).Dump()
("for 1,0: " + a2.ToString()).Dump()
@bjartwolf
bjartwolf / 1d.fs
Last active August 29, 2015 13:59
[<Measure>] type Length
[<Measure>] type Area = Length*Length
let area (a : float<Length>) (b: float<Length>) = 2.0*a*b
let a1:float<Area> = area 0.0<Length> 1.0<Length>
let a2:float<Area> = area 1.0<Length> 0.0<Length>
let a3:float<Area> = area 1.0<Length> 1.0<Length>
("for 0,1: " + a1.ToString()).Dump()
("for 1,0: " + a2.ToString()).Dump()
("for 1,1, circle should be pi: " + a3.ToString()).Dump()
@bjartwolf
bjartwolf / 1e.s
Last active August 29, 2015 13:59
[<Measure>] type Length
[<Measure>] type Area = Length*Length
let area (a : float<Length>) (b: float<Length>) = System.Math.PI*a*b
let a1:float<Area> = area 0.0<Length> 1.0<Length>
let a2:float<Area> = area 1.0<Length> 0.0<Length>
let a3:float<Area> = area 1.0<Length> 1.0<Length>
("for 0,1: " + a1.ToString()).Dump()
("for 1,0: " + a2.ToString()).Dump()
("for 1,1, circle should be pi: " + a3.ToString()).Dump()
[<Measure>] type m
[<Measure>] type s
[<Measure>] type kg
[<Measure>] type N = kg m / s / s
let a = 9.81<m/s/s>
let mass = 10.0<kg>
let f = a*mass
let pow3 (x:float<'u>):float<'u^3> =
let power = pown (float x) 3
open System
open System.IO
open FsCheck
open FsCheck.Xunit
[<Measure>] type m
[<Measure>] type Area = m^2
[<Measure>] type Volume = Area*m
let f (h:decimal<m>) = h
@bjartwolf
bjartwolf / 2.5.2.fs
Created April 21, 2014 18:41
2.5.2.fs
let VolumeNoHeightis0(a:decimal<m>) =
(a <= 10000000000m<m> && a >= 0m<m>) ==>
(lazy (V 0m<m> a a = 0m<m^3>))
Check.Quick VolumeNoHeightis0
@bjartwolf
bjartwolf / 2.5.3.fs
Created April 21, 2014 18:49
2.5.3.fs
let RoundM3 (cubic:decimal<m^3>): decimal<m^3> = Math.Round(cubic * 1m<m^-3>,10)*1m<m^3>
let VolumeAIsBEqualssquare((a:decimal<m>), (h:decimal<m>)) =
RoundM3 (V h a a) = RoundM3( a * a * h )
let twoDecimals = Arb.generate<decimal<m>> |> Gen.suchThat ((<) 0m<m>) |> Gen.suchThat ((>) 1000000m<m>) |> Gen.two |> Arb.fromGen
Check.Quick (Prop.forAll twoDecimals VolumeAIsBEqualssquare)
@bjartwolf
bjartwolf / 2.5.3.fs
Created April 21, 2014 19:00
2.5.3.fs
let g (a: decimal<m>) (b: decimal<m>):decimal<m^2> = (a*a + b*b) / 2m