Consider the following code, which declares an abstract base class called shape and another class called square which inherits from shape:
open System
[<AbstractClass>]
type shape() =
abstract area : int
type square(side) =
inherit shape()
override this.area = side * side
let return_square(n): shape =
new square(n)
[<EntryPoint>]
let main argv =
let foo = new square (3)
printfn "%d" foo.area
let bar = return_square(4)
printfn "%d" bar.area
0 // Return 0 to OS
The creation of foo works fine, but when I attempt to return a shape from return_square I receive the following error message:
This expression was expected to have type
'shape'
but here has type
'square'
Can anyone shed some light as to what I'm doing wrong? Shouldn't I be able to return a square since it's a type of shape?
Many TIA