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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id EAFABBC57 for ; Tue, 8 Jun 2010 18:24:10 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjUCAAsLDkzRVdS0imdsb2JhbACDHZsbCBUBAQEKCQwHDwUfrkg5ggKFSC6ITwEBAwWBIYMCbgQ X-IronPort-AV: E=Sophos;i="4.53,385,1272837600"; d="scan'208";a="51988474" Received: from mail-px0-f180.google.com ([209.85.212.180]) by mail3-smtp-sop.national.inria.fr with ESMTP; 08 Jun 2010 18:24:10 +0200 Received: by pxi17 with SMTP id 17so1591524pxi.39 for ; Tue, 08 Jun 2010 09:24:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:content-type; bh=MFH4IIduJjjIHFtc+dvtLuWHD5jyq4NPaMYM8DHZu58=; b=j/EYWQpnUs2wbh7hRfJcy/h3p8uiO8UtKph/xpw7e9OhaZyKeujiRNQHmdpEvOZYTf vBC9TxjFmf1g7mstwErkUgzNttHkAMnUNA6MWf0tJTcD7rt8alosNe8UZTHALuHOa7cJ SIUgcVjAgCZI8o0aXwdjqAzMm/Ibk09lxbivs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=BREaY7NWhG8qeugHH5/fifBLmHZHxDu2Xpl7R99BDqjaOAju3xY9poYGzqjtMmeDDS FEAs5F5io/DaAJVML6Y4pmVrgsRW6+SLh+Ni5JgOVX7GshwO6lYcHzv8ixCUjUmTFayV zezFVMi2TyPU8rrCXYD8AsxFWySOsqCGbrbQg= Received: by 10.229.184.203 with SMTP id cl11mr6118215qcb.178.1276014247510; Tue, 08 Jun 2010 09:24:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.77.156 with HTTP; Tue, 8 Jun 2010 09:23:47 -0700 (PDT) In-Reply-To: <4C0E6561.20207@inescporto.pt> References: <4C0E6561.20207@inescporto.pt> From: Paolo Donadeo Date: Tue, 8 Jun 2010 18:23:47 +0200 Message-ID: Subject: Re: [Caml-list] Escaped string in sexplib To: caml-list caml-list Content-Type: text/plain; charset=UTF-8 X-Spam: no; 0.00; sig:01 val:01 val:01 struct:01 sexp:01 sexp:01 blog:98 blog:98 cryptokit:01 cryptokit:01 encode:01 encode:01 caml-list:01 functions:01 data:02 I'm using Sexplib to store and retrieve the sessions of a web application into a data base. A "session" has this signature: module type SESSION_DATA = sig type t val default : t val string_of_t : t -> string (* Is this what you want? *) val t_of_string : string -> t (* Is this what you want? *) end and the concrete session, which is a blog session, is: module Blog_session = struct type user = { email : string; passwd : string; first_name : string option; last_name : string option; displ_name : string option; website : string option } with sexp type t = | Anonymous | Logged of user with sexp let default = Anonymous let string_of_t = sexp_of_t |- Sexplib.Sexp.to_string_hum |- hex_encode let t_of_string s = try s |> hex_decode |> Sexplib.Sexp.of_string |> t_of_sexp with Sexplib.Conv.Of_sexp_error (_, _) -> default end Functions "hex_encode" and "hex_decode" are trivially implemented using Cryptokit: let hex_encode = Cryptokit.transform_string (Cryptokit.Hexa.encode ()) let hex_decode = Cryptokit.transform_string (Cryptokit.Hexa.decode ()) The operators (|-) and (|>) are defined as always: http://thelema.github.com/batteries-included/hdoc/BatPervasives.html#6_Fundamentalfunctionsandoperators Hope this helps, -- Paolo