Parametric polymorphism: Difference between revisions

Content added Content deleted
(added objc)
Line 573: Line 573:
value: T
value: T
left, right: Tree[T]</lang>
left, right: Tree[T]</lang>

=={{header|Objective-C}}==
{{trans|C++}}
{{works with|Xcode|7}}
<lang objc>@interface Tree<T> : NSObject {
T value;
Tree<T> *left;
Tree<T> *right;
}

- (void)replaceAll:(T)v;
@end

@implementation Tree
- (void)replaceAll:(id)v {
value = v;
[left replaceAll:v];
[right replaceAll:v];
}
@end</lang>
Note that the generic type variable is only used in the declaration, but not in the implementation.


=={{header|OCaml}}==
=={{header|OCaml}}==