summaryrefslogtreecommitdiff
path: root/tnslc/tests/complex/generics.tnsl
blob: 3f624745a3610cd43e6117cd155b12295c895091 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
struct ListNode (type T) {
    T element,
    ~ListNode(T) next
}

/; method ListNode
    /; get_el [T]
        return self.element
    ;/

    /; get_next [ListNode(T)]
        return self.next`
    ;/
;/

struct ReferenceNode (type T) extends ListNode(T`) {
    super
}

/; method ReferenceNode
    /; change_ref (~T new_ref)
        ~self.element = new_ref
    ;/
;/

struct List(type T) {

}

# Generic (type T)
# Unknown generic (?)
# Ref to a type (type T) -> T`
#  Ref types can be used interchangably with their referenced type while pointer types can not
#  Variables typed by reference have the additional trait that you can
#  set the address of that variable