Reputation: 1197
I am a F# newbie. What is wrong with this code?
let setCategory (terminal: MerchantTerminal)
terminal.Category <- Nullable(MerchantTerminalCategory.NotSet)
()
Compiler telling me "Unexpected symbol '<-' in binding. Expected '=' or other token"
MerchantTerminal is C# type:
public class MerchantTerminal
{
public MerchantTerminalCategory? Category { get; set; }
}
MerchantTerminalCategory is C# enum
public enum MerchantTerminalCategory
{
NotSet = 0,
//other values
}
Upvotes: 2
Views: 608
Reputation: 11872
type MerchantTerminalCategory = NotSet=0 | Set=1
type MerchantTerminal() =
let mutable category =
new System.Nullable<MerchantTerminalCategory>()
member this.Category
with get() = category
and set(value) = category <- value
Your usage would look something like this. You were only missing the assignment =
op here.
let setCategory (terminal: MerchantTerminal) = //you were missing the assignment "=" op here
terminal.Category <- Nullable(MerchantTerminalCategory.NotSet)
()
As a friendly "code comment" suggestion, one of the benefits of using a construct like that of an enum is to avoid the use of null. If at all possible you should pull out the nullable part and leverage the available states of the enum to represent a default "NotSet" state possibly leveraging what you already have available or via a new state.
Upvotes: 1
Reputation: 80744
You're missing an equal sign in your let
definition. It needs to be right before the body, like let x = 5
or let f x = x + 5
.
Like this:
let setCategory (terminal: MerchantTerminal) =
terminal.Category <- Nullable(MerchantTerminalCategory.NotSet)
()
Upvotes: 4