[back]

Updating Recent Posts

An online post (defined by the record type post below) has a title, content, and timestamp. A user is defined by a record type with many fields (see below), but the important fields for this problem are

These fields have the further property that every post in old_posts is older than every post in recent_posts (i.e., their timestamps are smaller).

type post = {
  title : string;
  content : string;
  timestamp : int;
}

type user = {
  username : string;
  email : string;
  time_joined : int;
  is_paid_user : bool;
  balance : int;
  next_payment_time : int;
  is_paused : bool;
  num_followers : int;
  num_likes : int;
  old_posts : post list;
  recent_posts : post list;
}

Implement the function

val update_recent : user -> int -> int -> user

so that update_recent u time stale is a new user with the following properties:

Examples

let p t = {title="";content="";timestamp=t}
let mk op rp = {
  username = "" ;
  email = "" ;
  time_joined = 0 ;
  is_paid_user = true ;
  balance = 0 ;
  next_payment_time = 0 ;
  is_paused = true ;
  num_followers = 0 ;
  num_likes = 0 ;
  old_posts = op ;
  recent_posts = rp ;
}
let _ = assert (update_recent (mk [] [p 30;p 20;p 10;p 0]) 50 30 = mk [p 20;p 10;p 0] [p 30])