Created
October 15, 2012 09:39
-
-
Save LeastFixedPoint/3891697 to your computer and use it in GitHub Desktop.
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 hcf a b = | |
if a = 0u then b | |
elif a<b then hcf a (b - a) | |
else hcf (a - b) b | |
type Fraction = | |
{ n : uint32; d : uint32 } | |
override this.ToString() = | |
if (this.d = 1u) | |
then this.n.ToString() | |
else this.n.ToString() + "/" + this.d.ToString() | |
static member (+) (f1 : Fraction, f2 : Fraction) = | |
let nTemp = f1.n * f2.d + f2.n * f1.d | |
let dTemp = f1.d * f2.d | |
let hcfTemp = hcf nTemp dTemp | |
{ n = nTemp / hcfTemp; d = dTemp / hcfTemp } | |
let f a b = a + b | |
let fraction1 = { n = 2u; d = 3u } | |
let fraction2 = { n = 1u; d = 2u } | |
let result1 = f fraction1 fraction2 | |
let r2 = f 5 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment