Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Paolo Donadeo <p.donadeo@gmail.com>
To: caml-list caml-list <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Escaped string in sexplib
Date: Tue, 8 Jun 2010 18:23:47 +0200	[thread overview]
Message-ID: <AANLkTikXhoT3Ifmgr6Njd2UCQ4ssCOeoCLKAMq7YwLHN@mail.gmail.com> (raw)
In-Reply-To: <4C0E6561.20207@inescporto.pt>

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


  reply	other threads:[~2010-06-08 16:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-08 15:44 Hugo Ferreira
2010-06-08 16:23 ` Paolo Donadeo [this message]
2010-06-08 19:10   ` [Caml-list] " Hugo Ferreira
2010-06-08 16:52 ` Markus Mottl
2010-06-08 18:52   ` Hugo Ferreira
2010-06-08 19:30     ` Hugo Ferreira
2010-06-09  7:39       ` Paolo Donadeo
2010-06-09  8:02         ` Hugo Ferreira
2010-06-08 19:36     ` Markus Mottl
2010-06-08 19:40       ` Hugo Ferreira
2010-06-08 19:42     ` Török Edwin
2010-06-09  6:40       ` Hugo Ferreira

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=AANLkTikXhoT3Ifmgr6Njd2UCQ4ssCOeoCLKAMq7YwLHN@mail.gmail.com \
    --to=p.donadeo@gmail.com \
    --cc=caml-list@yquem.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