Parametric polymorphism: Difference between revisions

Content deleted Content added
No edit summary
Line 226:
? t :Tree[int]
# value: <tree></lang>
 
 
=={{header|F_Sharp|F#}}==
 
<lang fsharp>
namespace RosettaCode
 
type BinaryTree<'T> =
| Element of 'T
| Tree of 'T * BinaryTree<'T> * BinaryTree<'T>
member this.Map(f) =
match this with
| Element(x) -> Element(f x)
| Tree(x,left,right) -> Tree((f x), left.Map(f), right.Map(f))
</lang>
 
We can test this binary tree like so:
<lang fsharp>
let t1 = Tree(2, Element(1), Tree(4,Element(3),Element(5)) )
let t2 = t1.Map(fun x -> x * 10)
</lang>
 
 
=={{header|Haskell}}==