我的程序正在警告我(程序主模块为空:运行时将不会发生任何事情),这是否与我需要将存款成员放在提款成员之前的事实有关(因为那样会不是程序中要使用的任何东西)
type Account =
{accountNumber:string; mutable balance:float}
member this.Withdraw(cash:float) =
if cash > this.balance then
Console.WriteLine("Insufficient Funds. The Amount you wish to withdraw is greater than your current account balance.")
else
this.balance <- this.balance - cash
Console.WriteLine("You have withdrawn £" + cash.ToString() + ". Your balance is now: £" + this.balance.ToString())
member this.Deposit(cash:float) =
this.balance <- this.balance + cash
Console.WriteLine("£" + cash.ToString() + " Cash Deposited. Your new Balance is: £" + this.balance.ToString())
member this.Print() =
Console.WriteLine("Account Number: " + this.accountNumber)
Console.WriteLine("Balance: £" + this.balance.ToString())
程序应定义一个名为Account的f#类型,其中包含一个accountNumber(字符串)和balance(浮动)字段。该类型应包括用于将资金提取和存入帐户的方法,以及在控制台内的一行上显示字段值的打印成员。如果提款金额大于帐户余额,则应取消交易并显示适当的消息。
答案 0 :(得分:3)
几乎所有以任何编程语言编写的程序都需要一个入口点。 Here's是F#中main
的文档。
大多数裸露的F#程序都将以main
函数开头,该函数看起来像这样:
[<EntryPoint>]
let main args =
printfn "Arguments passed to function : %A" args
// Return 0. This indicates success.
0
您需要将自己的逻辑放入main
。