Skip to content

Instantly share code, notes, and snippets.

@matarillo
Last active March 12, 2023 18:29
Show Gist options
  • Save matarillo/b1d9ec8bb16627288b2c33917f3e5130 to your computer and use it in GitHub Desktop.
Save matarillo/b1d9ec8bb16627288b2c33917f3e5130 to your computer and use it in GitHub Desktop.
type Polynominal<'a>(x : 'a) =
static member op_Implicit (x : 'a) = Polynominal x
type Rational<'a>(x : 'a) =
class end
let x : Rational<Polynominal<float>> = Rational 1.0
printfn "%A" x
@matarillo
Copy link
Author

matarillo commented Mar 12, 2023

Generic Mathにからめて、こういうコードの方が良かっただろうか

type Polynominal<'a>(x : 'a list) =
    static member inline One with get () = Polynominal [LanguagePrimitives.GenericOne]

type Rational<'a>(x : 'a, y : 'a) =
    static member inline from x = Rational (x, LanguagePrimitives.GenericOne)

let x = Rational (3, 5)                      // 3 / 5
let y = Rational<_>.from 2.5                 // 2.5 / 1.0
let z = Rational<_>.from (Polynominal [4.2]) // Polynominal [4.2] / Polynominal [1.0]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment