I have this code:
let maximumResidual = 50.0m
let calculateResidual balance = if balance < maximumResidual then balance else maximumResidual
type BasicAccountDetails =
{ Balance: decimal }
type JointAccount =
{ Primary: string
Secondary: string
Balance: decimal }
type PersonalAccount =
{ Name: string
Balance: decimal }
member this.makeJointWith (addition: PersonalAccount) =
let thisResidual = calculateResidual this.Balance
let additionResidual = calculateResidual addition.Balance
( { Primary = this.Name
Secondary = addition.Name
Balance = (this.Balance - thisResidual) + (addition.Balance - additionResidual) } ,
{ this with Balance = thisResidual },
{ addition with Balance = additionResidual } )
type Account =
| Personal of PersonalAccount
| Joint of JointAccount
let janesAccount = Personal { Name = "Jane"; Balance = 200.0m }
let bobsAccount = Personal { Name = "Bob"; Balance = 40.0m }
let maryAndAbesAccount = Joint { Primary = "Mary"; Secondary = "Abe"; Balance = 230.0m }
let accounts : Account list = [ janesAccount; bobsAccount; maryAndAbesAccount ]
let makeJointAccount account1 account2 =
match account1, account2 with
| Personal personal1, Personal personal2 -> Ok <| personal1.makeJointWith personal2
| Joint _, _
| _, Joint _ -> Error <| "cannot make a joint account from a joint account"
let result = makeJointAccount janesAccount bobsAccount
When I select it all and execute it in the FSI I get the error:
error FS0193: internal error: Could not load type 'PersonalAccount' from assembly 'FSI-ASSEMBLY, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
However, when I execute all of the code except the last line in the FSI, and then, separately, execute the last line, it works:
val result: Result<(JointAccount * PersonalAccount * PersonalAccount),string>
= Ok ({ Primary = "Jane"
Secondary = "Bob"
Balance = 150.0M }, { Name = "Jane"
Balance = 50.0M }, { Name = "Bob"
Balance = 40.0M })
Is there something I am doing wrong?
I had a little look around the web and found these seemingly-related questions:
…but both are over five years old and those problems seem to be related to structs, which I’m not using.
FSI reports the version as:
Microsoft (R) F# Interactive version 12.0.1.0 for F# 6.0