Search code examples
syntaxf#type-providers

Defining type of TypeProvider


I am beginning to create my own Type Provider in F# but I fear a combination of poor documentation and personal inexperience (especially with the syntax) with F# is causing me trouble.

I am getting compiler errors stating that I need to declare members for my type. This leads me to believe I have some simple whitespace issues (Despite mimicking code on the MSDN webpage...)

My simple attempt at defining a Type:

type PoorlyWrittenQuestion =
    member briefIntro : string
    member poorDescription : string
    member confusingExample : string

I'm sure there are several problems here. Extra thanks for anyone that can not only correct these problems but also point me to a reliable source of documentation for F# 3.0 syntax.

Edit: This question may need a better title, as while this is the first step in my work on a TypeProvider, I don't think my problem is TypeProvider specific.


Solution

  • If you want to define class with non-static members than members name should start with some identifier indicating 'this' like:

    member this.briefInfo 
    

    or

    member x.briefInfo 
    

    (you can choose whatever id you want) or

    static member briefInfo 
    

    if you want static class member.

    Here is quick guide on OOP in F#: http://blogs.msdn.com/b/timng/archive/2010/04/05/f-object-oriented-programming-quick-guide.aspx

    Here is tutorial on how to create Type Providers: http://msdn.microsoft.com/en-us/library/hh361034.aspx

    Here is another tutorial: http://blog.mavnn.co.uk/type-providers-from-the-ground-up/