Abstract type: Difference between revisions

Content added Content deleted
(added Go)
Line 386: Line 386:
Now we can tag an object that conforms to the Interface:
Now we can tag an object that conforms to the Interface:
<lang genyris>tag StackInterface (XYZstack(.new))</lang>
<lang genyris>tag StackInterface (XYZstack(.new))</lang>

=={{header|Go}}==
Go's ''interface type'' is an abstract type. It defines a set of methods that a value must have.
<lang go>interface {
Method1(value float) int
SetName(name string)
GetName() string
}</lang>

A variable of an interface type can hold a value of any type that implements the methods that are specified in the interface. You don't need to explicitly "declare" that the type "implements" the interface or anything like that -- the compatibility is purely structural based on the methods.


=={{header|Haskell}}==
=={{header|Haskell}}==