// F# program that uses fractions.dll, which was written in C# // Please read fractions.cs first and pay attention to details. // uncomment following line if used in interactive console with .fsx extension // #r "d:\\files\\fractions.dll";; // EDIT PATH! open System; // define a list of numbers that can contain integers and fractions type number = Rat of fraction | Int of int;; type nlist = Cons of number*nlist | Nil;; // function that prints every element of an nlist: let rec printnl = function | Nil -> Console.WriteLine(""); // carriage return | Cons(Int(n),t) -> Console.Write(string(n)+" "); printnl t; | Cons(Rat(r),t) -> Console.Write(r.ToString()+" "); printnl t;; let half = fraction(1,2); let quarter = new fraction(1,4); // "new" is optional let M = Cons(Int(2),Cons(Rat(half),Cons(Int(4),Cons(Rat(quarter),Nil)))); printnl M; ///////////////////////////// // Compilation directions: // After installing Fsharp, // add path to directory containing the compiler, fsc.exe, // to windows system environment variable Path. // // Compile this program with // // fsc numlist.fs -r fractions.dll // // This will produce numlist.exe // // // Alternatively, rename this file with a .fsx suffix (Fsharp script), then // uncomment #r directive above and // run this program in Fsharp interactive mode by typing // #load "c:\\path..\\numlist.fsx";;