use std; import std::list::*; pure fn pure_length_go(ls: @List, acc: uint) -> uint { match *ls { Nil => { acc } Cons(_, tl) => { pure_length_go(tl, acc + 1u) } } } pure fn pure_length(ls: @List) -> uint { pure_length_go(ls, 0u) } pure fn nonempty_list(ls: @List) -> bool { pure_length(ls) > 0u } fn safe_head(ls: @List) -> T { assert is_not_empty(ls); return head(ls); } fn main() { let mylist = @Cons(@1u, @Nil); assert (nonempty_list(mylist)); assert (*safe_head(mylist) == 1u); }