Error: An annotation of the type may be required.

I am trying to return Name to the value of item.name, where item is an instance of a C # class.

fs file contains

namespace PatternMatch

type PatternMatch() = 
    member this.X = "F#"

namespace Items_

The fsx file contains

#load "PatternMatch.fs"
open PatternMatch

open Items_

type item = Item

let Name item = item.name //this line throws the error

let rec sentence s item  = function
    | s when s="Action" -> ""
    | s when s="Client" -> ""
    | s when s="Classifier" -> ""    
    | s when s="Container" -> ""    
    | s when s="ControlFlow" -> ""
    | s when s="Gaurd" -> ""
    | s when s="Name" -> Name item
    | s when s="ObjectFlow" -> ""    
    | s when s="Source" -> ""    
    | _ -> ""

let Name item = item.namegives an error message. Items_is the C # namespace, and Itemis the C # class inside.

All error:

Search for an object of an indefinite type based on information up to this point in the program. Type annotations may be required up to this point in the program to limit the type of object. This allows you to allow the search. C: \ Users \ jzbedocs \ Local Files \ Visual Studio 2010 \ Projects \ addin \ trunk \ PatternMatch \ Script.fsx 11 17 PatternMatch

+4
source share
1 answer

let Name item = item.name . item , , (. , - ...)

, , item item. , :

let Name (itemParameter:item) = itemParameter.name

, , , , , , ( ).

: , . , , :

> let Name (item:item) = item.name;;

val Name : item:item -> string // EW!

, - :

> let item (item:item) : item = item;;

val item : item:item -> item //Huh?

:

let rec sentence s item  = function
    | s when s="Action" -> ""
    | s when s="Client" -> ""
    | s when s="Classifier" -> ""    
    | s when s="Container" -> ""    
    | s when s="ControlFlow" -> ""
    | s when s="Gaurd" -> ""
    | s when s="Name" -> Name item
    | s when s="ObjectFlow" -> ""    
    | s when s="Source" -> ""    
    | _ -> ""

, :

let rec sentence s item  = 
    match s with
    | "Action" -> ""
    | "Client" -> ""
    | "Classifier" -> ""    
    | "Container" -> ""    
    | "ControlFlow" -> ""
    | "Gaurd" -> "" //Guard maybe?
    | "Name" -> Name item
    | "ObjectFlow" -> ""    
    | "Source" -> ""    
    | _ -> ""

, item ( repl):

> type Item() =
    member val name = "" with get,set
type item = Item

let Name (itemParameter:item) = itemParameter.name

let test = item();;
test.name <- "test"
Name test;;

val it : string = "test"
+4

All Articles