Skip to content

Instantly share code, notes, and snippets.

Created February 26, 2015 00:06
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 anonymous/d8e0e151c35f8784f895 to your computer and use it in GitHub Desktop.
Save anonymous/d8e0e151c35f8784f895 to your computer and use it in GitHub Desktop.
type Primitive with
member x.Length =
let rec calcLength =
function
| Circle (_,r) -> System.Math.PI * r * 2.
| Ellipse (_,r1,r2) -> System.Math.PI * 2. * sqrt( (r1 * r1 ) + (r2 * r2 ) / 2. )
| Square (_, w,_) -> w * 4.
| MultiPrimitive xs -> List.fold (fun c x -> c + calcLength x) 0. xs
calcLength x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment