Abstract type: Difference between revisions

Content added Content deleted
m (→‎{{header|Tcl}}: correct requirement)
Line 357: Line 357:
}
}
}</lang>
}</lang>
=={{header|F Sharp|F#}}==
A type with only abstract members and without constructors is an '''interface''' (when not marked with the <code>AbstractClass</code> attribte). Example:
<lang fsharp>type Shape =
abstract Perimeter: unit -> float
abstract Area: unit -> float

type Rectangle(width, height) =
interface Shape with
member x.Perimeter() = 2.0 * width + 2.0 * height
member x.Area() = width * height</lang>

A type that leaves some or all members unimplemented, is an '''abstract class'''. It has to be marked with the <code>AbstractClass</code> attribute. Example:
<lang fsharp>[<AbstractClass>]
type Bird() =
// an abstract (=virtual) method with default impl.
abstract Move : unit -> unit
default x.Move() = printfn "flying"
// a pure virtual method
abstract Sing: unit -> string

type Blackbird() =
inherit Bird()
override x.Sing() = "tra-la-la"

type Ostrich() =
inherit Bird()
override x.Move() = printfn "walking"
override x.Sing() = "hiss hiss!"</lang>

=={{header|Genyris}}==
=={{header|Genyris}}==
In Genyris by default there are no constructors. In effect all classes are Abstract until they are used to tag (describe) an object. This in keeping with the language's roots in Description Logic. To prevent the class ever being associated with an instance it suffices to force the validator to fail.
In Genyris by default there are no constructors. In effect all classes are Abstract until they are used to tag (describe) an object. This in keeping with the language's roots in Description Logic. To prevent the class ever being associated with an instance it suffices to force the validator to fail.