Advanced Functional Prog.


Interoperability with C#

Library can be generated in a similar manner:

dotnet new classlib -lang "F#" -n "Library" -o .

Then, the file named "Library.fs" can be edited:

module rec Library

type 't Exp = 
  | Val of 't 
  | Add of 't Exp * 't Exp

let v = Add (Val 1, Val 2)

let toString v = match v with
  | Val v       -> string v
  | Add (e1,e2) -> (toString e1)+"+"+(toString e2)

And then compiled into an dll:

dotnet build Library.fsproj
ls obj/Debug/net7.0/ # Library.dll