Abstract type: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(→‎{{header|Go}}: Rejigged this entry which didn't quite hang together previously.)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 218:
 
red orange
 
 
=={{header|Apex}}==
Line 322 ⟶ 321:
return
</lang>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
Line 889:
end
</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> attribute). 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|Fantom}}==
Line 921 ⟶ 950:
}
</lang>
 
=={{header|Forth}}==
{{works with|4tH|3.61.5}}
Line 1,035 ⟶ 1,065:
Rover is barking
</pre>
 
=={{header|F Sharp|F#}}==
A type with only abstract members and without constructors is an '''interface''' (when not marked with the <code>AbstractClass</code> attribute). 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}}==
Line 1,627 ⟶ 1,628:
}
</lang>
 
 
=={{header|Mathematica}}==
Line 2,029:
type ut = u t
type vt = v t</lang>
 
 
=={{header|Oforth}}==
Line 2,376 ⟶ 2,375:
 
1;</lang>
 
=={{header|Perl 6}}==
{{works with|rakudo|2015.12}}
 
Perl 6 supports roles, which are a bit like interfaces, but unlike interfaces in Java they can also contain some implementation.
 
<lang perl6>
use v6;
 
role A {
# must be filled in by the class it is composed into
method abstract() { ... };
 
# can be overridden in the class, but that's not mandatory
method concrete() { say '# 42' };
}
 
class SomeClass does A {
method abstract() {
say "# made concrete in class"
}
}
 
my $obj = SomeClass.new;
$obj.abstract();
$obj.concrete();
 
# output:
# made concrete in class
# 42
</lang>
 
=={{header|Phix}}==
Line 2,460 ⟶ 2,428:
(foo)
(bar) )</lang>
 
 
=={{header|PowerShell}}==
Line 2,667 ⟶ 2,634:
(define tom (new cat%))
(send tom say)
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
{{works with|rakudo|2015.12}}
 
Perl 6 supports roles, which are a bit like interfaces, but unlike interfaces in Java they can also contain some implementation.
 
<lang perl6>
use v6;
 
role A {
# must be filled in by the class it is composed into
method abstract() { ... };
 
# can be overridden in the class, but that's not mandatory
method concrete() { say '# 42' };
}
 
class SomeClass does A {
method abstract() {
say "# made concrete in class"
}
}
 
my $obj = SomeClass.new;
$obj.abstract();
$obj.concrete();
 
# output:
# made concrete in class
# 42
</lang>
 
Line 2,898 ⟶ 2,897:
obj.abstract(); # made concrete in class
obj.concrete(); # 42</lang>
 
=={{header|Simula}}==
Abtract Datatypes are declared using the VIRTUAL keyword.
10,327

edits