// One list can hold different kinds of values; unannotated fields and inputs mean Any.
class Node {
    public let value
    public var next: Node?
}

class LinkedList {
    var head: Node?

    fn prepend(value) {
        head = Node(value: value, next: head)
    }

    fn append(value) {
        let node = Node(value: value, next: null)
        if head == null {
            head = node
            return
        }
        var cursor = head
        while cursor.next != null {
            cursor = cursor.next
        }
        cursor.next = node
    }

    fn first() {
        if head == null { return null }
        return head.value
    }

    fn print_all() {
        var cursor = head
        while cursor != null {
            print(cursor.value)
            cursor = cursor.next
        }
    }

    fn len() {
        var count = 0
        var cursor = head
        while cursor != null {
            count = count + 1
            cursor = cursor.next
        }
        return count
    }
}

let items = LinkedList(head: null)
items.append(10)
items.append("hello")
items.append(1.5)
items.append(true)
items.print_all()
print(items.len()) // 4
print(type_of(items.first())) // Int64
print(cast<Int64>(items.first()) + 5) // 15
