Created
October 18, 2021 21:04
-
-
Save njlr/b6c641535f5070f7ff3103c40e829d74 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
type Circle<'t when 't : (static member Zero : 't) | |
and 't : (static member One : 't) | |
and 't : (static member (+) : 't * 't -> 't) | |
and 't : (static member (-) : 't * 't -> 't) | |
and 't : (static member (*) : 't * 't -> 't) | |
and 't : (static member (/) : 't * 't -> 't) | |
and 't : (static member (~-) : 't -> 't) | |
and 't : (static member op_Explicit : float -> 't) > = | |
{ | |
Radius : 't | |
} | |
#nowarn "77" // op_Explicit | |
module Circle = | |
open System | |
let inline area (circle : Circle< ^t>) = | |
let castFromFloat (x : float) = (^t : (static member op_Explicit : float -> ^t) (x) ) | |
castFromFloat Math.PI * circle.Radius * circle.Radius | |
printfn "%A" <| Circle.area { Radius = 1 } | |
printfn "%A" <| Circle.area { Radius = 1.0 } | |
printfn "%A" <| Circle.area { Radius = 1.0f } | |
(* | |
3 | |
3.141592654 | |
3.141592741f | |
*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment