WikiLuc

Guest connection: login: Guest, password: anonymous

User Tools

Site Tools


dit:cours:prog1:cours02

type ilist = int list;;
 
let empty() = ([]: ilist);;
 
let cons x (l: ilist) = (x::l: ilist);;
 
let car (l:ilist) = 
  match l with
  | x::_ -> x
  | _ -> failwith "car"
;;
 
let cdr (l: ilist) = 
  match l with
  | _::l' -> (l': ilist)
  | _ -> failwith "cdr"
;;
 
let is_empty (l: ilist) =
  match l with
  | [] -> true
  | _ -> false
;;
 
let rec print l = 
  if is_empty l then ()
  else begin 
    print_int (car l); 
    print_string " "; 
    print (cdr l) 
  end
;;

dit/cours/prog1/cours02.txt · Last modified: 2017/10/02 10:40 (external edit)