Abstract type: Difference between revisions
Content added Content deleted
(→{{header|Vlang}}: Rename "Vlang" in "V (Vlang)") |
No edit summary |
||
Line 999: | Line 999: | ||
} |
} |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|EMal}}== |
|||
{{trans|Go}} |
|||
<syntaxhighlight lang="emal"> |
|||
^|EMal doesn'r support abstract types with partial implementations, |
|||
|but we can use interfaces. |
|||
|^ |
|||
type Beast |
|||
interface |
|||
fun getKind = text by block do end |
|||
fun getName = text by block do end |
|||
fun getCry = text by block do end |
|||
end |
|||
type Dog implements Beast |
|||
model |
|||
text kind |
|||
text name |
|||
fun getKind = text by block do return me.kind end |
|||
fun getName = text by block do return me.name end |
|||
fun getCry = text by block do return "Woof" end |
|||
end |
|||
type Cat implements Beast |
|||
model |
|||
text kind |
|||
text name |
|||
fun getKind = text by block do return me.kind end |
|||
fun getName = text by block do return me.name end |
|||
fun getCry = text by block do return "Meow" end |
|||
end |
|||
type AbstractType |
|||
^|Beast b = Beast() # interface instantiation is not allowed|^ |
|||
fun bprint = void by Beast b |
|||
writeLine(b.getName() + ", who's a " + b.getKind() + ", cries: " + b.getCry() + ".") |
|||
end |
|||
^|instantiation works becaus a positional variadic constructor |
|||
|has been auto generated |
|||
|^ |
|||
var d = Dog("labrador", "Max") |
|||
Cat c = Cat("siamese", "Sammy") |
|||
bprint(d) |
|||
bprint(c) |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
Max, who's a labrador, cries: Woof. |
|||
Sammy, who's a siamese, cries: Meow. |
|||
</pre> |
|||
=={{header|F Sharp|F#}}== |
=={{header|F Sharp|F#}}== |