From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id F01D4BC57 for ; Thu, 16 Dec 2010 14:34:36 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApABANyjCU3Yi+wamWdsb2JhbACWBgEBji4VAQEBAQEICwoHESSxDodNLohchUoEhGWGGA X-IronPort-AV: E=Sophos;i="4.59,355,1288566000"; d="scan'208";a="84049707" Received: from sam.nabble.com ([216.139.236.26]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES256-SHA; 16 Dec 2010 14:34:36 +0100 Received: from isper.nabble.com ([192.168.236.156]) by sam.nabble.com with esmtp (Exim 4.69) (envelope-from ) id 1PTDyc-0004Se-Em for caml-list@inria.fr; Thu, 16 Dec 2010 05:34:34 -0800 Message-ID: <30472719.post@talk.nabble.com> Date: Thu, 16 Dec 2010 05:34:34 -0800 (PST) From: sieira To: caml-list@inria.fr Subject: [Caml-list] Caml light Callback MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: jaimito.hendrix@gmail.com X-Spam: no; 0.00; occupational:98 clientes:98 rec:01 rec:01 caml-list:01 callback:02 callback:02 caml:02 caml:02 lisp:02 string:02 string:02 latter:03 unit:03 unit:03 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.