Search code examples
f#type-providers

Can a type provider be used to generate a type extension?


I have a record type

type Foo = {mutable x:int; mutable y:int}

and I want to auto generate a clone function for it:-

type Foo with
  member m.clone() = {x=m.x;y=m.y}

Is it possible to generate this type extension using a type provider?


Solution

  • No, you can't define C#-style extension members or F#-style augmentations via type providers.

    Support for provided C#-style extension members was attempted for F# 4.0, but was ultimately cut. You can follow that discussion here, then here.