Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Mohamed Iguernlala <iguer.auto@gmail.com>
To: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: [Caml-list] better "encapsulation" for type Digest.t ?
Date: Wed, 8 Feb 2017 14:04:21 +0100	[thread overview]
Message-ID: <74f3ea0c-a93e-d8ae-6071-14a250baa662@gmail.com> (raw)

Hi,

I am wondering why the type t of Digest module is not abstract or
defined as private. Currently, this type is an alias of string. Thus,
one can easily make a mistake by providing a string instead of a
Digest.t to function Digest.to_hex, which raises an exception (ex1
below). The type-checker would help to catch this kind of errors if
Digest.t was abstract or private.

(*
   from Digest.mli:
     type t = string
     val to_hex : t -> string
     val string : string -> t
*)

let ex1 =
   try ignore (Digest.to_hex "foobar")
   with Invalid_argument("index out of bounds") -> Format.eprintf "Aie !@."

let ex2 =
   ignore (Digest.to_hex (Digest.string "foobar"));

- Mohamed.

-- 
Senior R&D Engineer, OCamlPro SAS
Research Associate, VALS team, LRI
Webpage: http://www.iguer.info
LinkedIn: https://fr.linkedin.com/in/mohamed-iguernlala-71515979

                 reply	other threads:[~2017-02-08 13:04 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=74f3ea0c-a93e-d8ae-6071-14a250baa662@gmail.com \
    --to=iguer.auto@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