* [Caml-list] Caml light Callback
@ 2010-12-16 13:34 sieira
0 siblings, 0 replies; only message in thread
From: sieira @ 2010-12-16 13:34 UTC (permalink / raw)
To: caml-list
I'm trying to implement some kind of callback menu in camllight
what I want is to store every menu entry and action as follows:
type menu == (string*string*triggered_function*args_for_that_function)
list;;
I've been working with C for years, so I may be suffering the consecuences
of my "occupational habits"
Here Is my sketch, where I can't find the way to ask lisp to generalize last
two parameters
(**** given a key, checks if it exists within the menu-entries list ***)
let rec seek = function
_,[] -> false
| x, (name,key,lfun,largs)::l -> if x=key then true
else seek (x,l);;
let rec run_op = function
_,[] -> ();
| selection,(name,key,lfun,largs)::l -> if selection = key then lfun
largs else run_op(selection,l);;
let rec draw_menu = function
[] ->
begin
print_string "\n> ";
end
| (text,key,_,_)::rest ->
begin
print_string ("\n"^key^"- "^text);
draw_menu(rest);
end;;
let rec run_menu = function
menu ->
begin
draw_menu menu;
let readen = read_line() in
begin
if seek(readen,menu) then run_op(readen,menu)
else ();
end;
run_menu menu;
end;;
let menu_customers = [("Option 1","1",print_string,"Hello world")];;
let menu_operations = [("Option 1","1",run_menu,menu_customers)];;
let menu_principal =
[("Clientes","1",run_menu,menu_customers);("Operaciones","2",run_menu,menu_operations)];;
________________________________
So, while menu_customers has type:
(string * string * (string -> unit) * string) list
I find that menu_operations has type:
(string * string * ((string * string * ('a -> unit) * 'a) list -> 'b) *
(string * string * (string -> unit) * string) list)
Thus, while print_string is (string -> unit), run_menu is ((string * string
* ('a -> unit) * 'a) list -> 'b)
and while "Hello world" is string, menu_customer is (string * string *
(string -> unit) * string) list.
Is there any way to generalize this two latter parameters, or should I find
another way to do this?
--
View this message in context: http://old.nabble.com/Caml-light-Callback-tp30472719p30472719.html
Sent from the Caml Discuss mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2010-12-16 13:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-16 13:34 [Caml-list] Caml light Callback sieira
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox