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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 1A0F1BBAF for ; Sat, 13 Nov 2010 19:33:08 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuYBAOdo3kzVpUAWi2dsb2JhbACiaQEBCwsKBw8FH70WhUoEilc X-IronPort-AV: E=Sophos;i="4.59,191,1288566000"; d="scan'208";a="86934387" Received: from mailout-de.gmx.net (HELO mail.gmx.net) ([213.165.64.22]) by mail1-smtp-roc.national.inria.fr with SMTP; 13 Nov 2010 19:33:07 +0100 Received: (qmail invoked by alias); 13 Nov 2010 18:33:07 -0000 Received: from ip-88-153-45-124.unitymediagroup.de (EHLO mail.gmx.net) [88.153.45.124] by mail.gmx.net (mp050) with SMTP; 13 Nov 2010 19:33:07 +0100 X-Authenticated: #20429361 X-Provags-ID: V01U2FsdGVkX19t8IcdXultjG36Qjf0OnbBUXHhxVndTlI6jZzJex 52vYY6owChJcy/ Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes To: "caml-list@yquem.inria.fr" Date: Sat, 13 Nov 2010 19:33:07 +0100 Subject: Ocsigen and forms MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Till Crueger" Message-ID: User-Agent: Opera Mail/10.63 (Linux) X-Y-GMX-Trusted: 0 X-Spam: no; 0.00; recursive:01 suff:01 params:01 printf:01 sprintf:01 webservices:98 todos:98 todos:98 heute:98 functions:01 int:01 int:01 variant:02 expression:02 expression:02 Hi, I am still trying to get my head around Ocsigen and Eliom. The links I got last time helped a lot to figure out how to build webservices with ocsigen. However there are still many occasions, when I get stuck. Right now I am trying to build a page with a form, that sends the user to a page generated by the same service. The same service should also be linked in a navigation area on the page. To do this I am creating the service, then I the navigation area and finally use some helper functions to build the page including the navigation. This is a bit like retying the knot to reduce the problems with recursive function. All this worked really nice until I tried to add the form to the same page. Once I tried this I got a really bad type error: Error: This expression has type (int * (int * int), unit, [> `Attached of Eliom_services.get_attached_service_kind Eliom_services.a_s ] as 'a, [ `WithSuffix ], [ `One of int ] Eliom_parameters.param_name * ([ `One of int ] Eliom_parameters.param_name * [ `One of int ] Eliom_parameters.param_name), unit, [> `Registrable ]) Eliom_services.service but an expression was expected of type (int * (int * int), unit, [< `Attached of Eliom_services.get_attached_service_kind Eliom_services.a_s & Eliom_services.internal Eliom_services.a_s | `Nonattached of [ `Get ] Eliom_services.na_s & Eliom_services.getpost Eliom_services.na_s ] as 'b, [< Eliom_services.suff ], [< int Eliom_parameters.setoneradio ] Eliom_parameters.param_name * ([< int Eliom_parameters.setoneradio ] Eliom_parameters.param_name * [< int Eliom_parameters.setoneradio ] Eliom_parameters.param_name), 'c, [ `Registrable ]) Eliom_services.service Type 'a is not compatible with type 'b = [< `Attached of Eliom_services.get_attached_service_kind Eliom_services.a_s & Eliom_services.internal Eliom_services.a_s | `Nonattached of [ `Get ] Eliom_services.na_s & Eliom_services.getpost Eliom_services.na_s ] Type Eliom_services.get_attached_service_kind = [ `External | `Internal of Eliom_services.servcoserv * [ `Get ] ] is not compatible with type Eliom_services.internal = [ `Internal of Eliom_services.servcoserv * Eliom_services.getpost ] The second variant type does not allow tag(s) `External The reduced code for this example is: open Lwt open XHTML.M open Eliom_services open Eliom_parameters open Eliom_sessions open Eliom_predefmod.Xhtml let div_with_class klass ?(a = []) l = div ~a:(a_class [klass] :: a) l let div_with_id id ?(a = []) l = div ~a:(a_id id :: a) l let make_page navigation htmlhead content = return ( html (head htmlhead []) (body [div_with_id "navigation" (navigation ()); div_with_id "content" content ] ) ) let listservice = new_service ~path:["todos"] ~get_params:(suffix (int "year" ** int "month" ** int "day")) () let choose_date service sp = let form (day,(month,year)) = [p [int_input ~input_type:`Text ~name:day (); int_input ~input_type:`Text ~name:month (); int_input ~input_type:`Text ~name:year (); string_input ~input_type:`Submit ~value:"Click" ()]] in div_with_clas "datechooser" [ get_form service sp form ] let make make_service listservice db = register listservice (fun sp (year,(month,day)) () -> let titlestring = Printf.sprintf "Todos für %i.%i.%i" day month year in let htmlhead = title (pcdata titlestring) in let content = [ h1 [pcdata titlestring]; br (); choose_date listservice sp ] in make_service sp htmlhead content ) let navigation sp () = let today = Date.get_today () in let tomorrow = Date.next_day today in let yesterday = Date.previous_day today in [ul ~a:[a_class ["level1"]] (li [ div_with_class "li" [pcdata "Todos"]; ul ~a:[a_class ["level2"]] (li [ div_with_class "li" [a listservice sp [pcdata "Heute"] (1,(2,3))] ] ) [] ]) [] ] let make_service sp htmlhead content = make_page (navigation sp) htmlhead content let _ = make make_service listservice