The option type, along with other native F# types such as tuples, are defined in the FSharp.core.dll library (called fslib.dll in older versions of F#). To use these types from C# you just need to add a refernce to this library. Union types like option look a little strange to C# but are still usable.

Cheers,
Rob

By on 3/5/2008 12:47 AM ()

I've already added the fslib.dll library, which removed me an error but i'm still not able to do wath i want.

fsharpFile.fs

1
2
let returnAList (number:int) = [number;number;number];;

csharpFile.cs

1
2
List<int> myList = ProjectFsharp.fsharpFile.returnAList(5);

but that line on C# file gives me: "<i>Cannot implicitly convert type 'Microsoft.Fsharp.Collections.List<int>' to 'system.Collections.Generic.List<int><i>'" Even if i explicitly put the cast it gives an error. any way to fix this? Also, if i wanted to receive a tuple list from F#, how would i receive it in C#? Should i had to make an object with the same types of the tuple elements of the list? or ? Little example please? :)

By on 3/21/2008 2:40 PM ()

A C# list (System.Collections.Generic.List) and an F# list (Microsoft.FSharp.Collections.List) are completely different types. A C# list has a constructor that accepts an IEnumerable to initialize the list, and an F# list implements IEnumerable, so you could write

1
List<int> myList = new List<int>(ProjectFsharp.fsharpFile.returnAList(5));

F# tuples are represented in C# as the types Microsoft.FSharp.Core.Tuple, with varying number of type parameters depending on the size of the tuple. So you could write

1
2
3
4
using System.Collections.Generic;
using Microsoft.FSharp.Core;

List<Tuple<int,int>> myListOfIntIntTuples;
By on 3/21/2008 7:04 PM ()

Working :)

Thanks mate!

By on 3/22/2008 4:01 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper