Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module type TRIP =
- sig
- type trip;;
- val create_trip : int -> int -> trip list -> trip list
- val delete_trip : int -> trip list -> trip list
- val list_trip : int -> trip list -> trip list
- end
- module Trip : TRIP =
- struct
- type trip = (int * int);;
- let rec create_trip digit speed listy = (digit, speed)::listy;;
- let rec delete_trip index listy = [];;
- let rec list_trip n = function
- | (digit, speed)::tail -> Printf.printf "%d %d\n" digit speed; (digit, speed)::(list_trip n tail)
- | [] -> []
- end;;
- let rec matcher = function
- | str -> match (List.hd (Str.split (Str.regexp "[ \t]+") str)) with
- | "create" -> Printf.printf "create\n"
- | "delete" -> Printf.printf "delete\n"
- | "list" -> Printf.printf "list\n"
- | _ -> Printf.printf "WTF bro\n"
- ;;
- let rec debugger = function
- | head::tail -> Printf.printf "%s\n" head; debugger tail
- | [] -> []
- ;;
- (* let lines = ref [] in
- try
- while true; do
- lines := (matcher (read_line ())) :: !lines
- done; !lines
- with End_of_file ->
- debugger (List.rev !lines) ;; *)
- type mytype = Trip.trip list;;
- let read_lines name : Trip.trip list =
- let ic = open_in name in
- let try_read () =
- try Some (matcher (read_line ())) with End_of_file -> None in
- let rec loop acc = match try_read () with
- | Some s -> loop (s :: acc)
- | None -> close_in ic; List.rev acc in
- loop []
Add Comment
Please, Sign In to add comment