From: sieira <jaimito.hendrix@gmail.com>
To: caml-list@inria.fr
Subject: [Caml-list] Caml light Callback
Date: Thu, 16 Dec 2010 05:34:34 -0800 (PST) [thread overview]
Message-ID: <30472719.post@talk.nabble.com> (raw)
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.
reply other threads:[~2010-12-16 13:34 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=30472719.post@talk.nabble.com \
--to=jaimito.hendrix@gmail.com \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox