From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 84DA37EEBF for ; Fri, 24 Jul 2015 16:04:28 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of ilitzroth@gmail.com) identity=pra; client-ip=209.85.192.48; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="ilitzroth@gmail.com"; x-sender="ilitzroth@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of ilitzroth@gmail.com designates 209.85.192.48 as permitted sender) identity=mailfrom; client-ip=209.85.192.48; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="ilitzroth@gmail.com"; x-sender="ilitzroth@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-qg0-f48.google.com) identity=helo; client-ip=209.85.192.48; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="ilitzroth@gmail.com"; x-sender="postmaster@mail-qg0-f48.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BMAQD4RLJVmzDAVdFchFIGsEGUOgdMAQEBAQEBEgEBAQEBBgsLCSEuhDwRBBkBGx4DEgkHNwIkAREBBQE9God2AQMSplCCBYEsPjGLP4FsgnmLIAoZJw1XhH4BBQ6QZIJSgUMFlGOMPJdaEiOBFReEDjwxgksBAQE X-IPAS-Result: A0BMAQD4RLJVmzDAVdFchFIGsEGUOgdMAQEBAQEBEgEBAQEBBgsLCSEuhDwRBBkBGx4DEgkHNwIkAREBBQE9God2AQMSplCCBYEsPjGLP4FsgnmLIAoZJw1XhH4BBQ6QZIJSgUMFlGOMPJdaEiOBFReEDjwxgksBAQE X-IronPort-AV: E=Sophos;i="5.15,538,1432591200"; d="scan'208";a="171519730" Received: from mail-qg0-f48.google.com ([209.85.192.48]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 24 Jul 2015 16:04:27 +0200 Received: by qged69 with SMTP id d69so11022456qge.0 for ; Fri, 24 Jul 2015 07:04:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=2L1I9TeUbNJP+cChP5LO8AYUrTY9KDRYMuL+/1qlcBA=; b=z+7GZfzceTLbFQw/KRxBXeIhe5P+niashpJV9wV1UHCOahTgC6PmfMi6yYqqpu0foe Zl9Ws7YPFCtKhFIz/rlJgVMv7BZ164lOjzGJG51A0WExnMHaj6yH0yMmB+uX/RhvLCRg XUpFzXRPRUsHt0nbsWSs3xmCsXDi3iKaNtTe8MlOBGg0W1FxWiaIyO3R7U2JH75SPs51 YYmWcXVp/C55Bv3ebL5/G/pJF3Bjh7YeRGC1JBjM3xWLkT17bEk4N5VzVQn5R0gsGkjN 5XZP0+3VkwhVIr7wYVmJhI4b8gxpxa8w9/EcpH8fVpQf1w1PGVAZwCHy7nIKrxlOf8rc cBrQ== X-Received: by 10.55.40.26 with SMTP id o26mr20214751qkh.36.1437746666754; Fri, 24 Jul 2015 07:04:26 -0700 (PDT) MIME-Version: 1.0 Received: by 10.96.205.97 with HTTP; Fri, 24 Jul 2015 07:04:07 -0700 (PDT) From: immanuel litzroth Date: Fri, 24 Jul 2015 16:04:07 +0200 Message-ID: To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=001a11440e22595922051b9f7b5f Subject: [Caml-list] Question on private type abbreviations --001a11440e22595922051b9f7b5f Content-Type: text/plain; charset=UTF-8 I have a question related to private type abbreviations I'm interfacing C++ and ocaml and I want to make sure that the ranges of integer types are correct and reflect them in the ocaml interface. So I define type uint8 = private int and type int8 = private int same for the other sizes/signedness and the appropriate functions to do range checking (those are external and use std::numeric limits) external uint8 : int -> uint8 = "make_uint8" ... this gives typesafety and avoids boxing/unboxing and makes sure that the user can only pass values that are range checked at the earliest opportunity. Now I wanna check my code for all the types I wanna use 1 checking function something like this: let test_conversions (the_fun : int -> 't) (the_val : int) = try let the_t = the_fun the_val in Printf.printf "Numbers are %d\n" (the_t : 't :> int) with | Invalid_argument str -> Printf.printf "Error: %s" str let () = test_conversions uint8 1 -> will work .. let () = test_conversions uint64 (-1) -> will print Error... Now this doesn't typecheck because the type var 't in the signature is too general. what I need to put there is "a type coercible to int" Is that possible? Is there some way to achieve this? Thanks in advance, Immanuel --001a11440e22595922051b9f7b5f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I have a question related to private type abbreviatio= ns
I'm interfacing C++ and ocaml and I want to make sure that= the ranges of integer types are correct and reflect them in the ocaml inte= rface.

So I define
type uint8 =3D pr= ivate int
and=C2=A0
type int8 =3D private int
same for the other sizes/signedness
and the appropriate function= s to do range checking (those are external and use=C2=A0
std:= :numeric limits)
external uint8 : int -> uint8 =3D "make_= uint8"
...=C2=A0
this gives typesafety and avoids = boxing/unboxing and makes sure that the user can
only pass values= that are range checked at the earliest opportunity.

Now I wanna check my code
for all the types I wanna use 1 chec= king function something like this:

let test_c= onversions =C2=A0 (the_fun : int -> 't) =C2=A0(the_val : int) =3D
=C2=A0 try
=C2=A0 =C2=A0 let the_t =3D the_fun the_val in=
=C2=A0 =C2=A0 Printf.printf "Numbers are %d\n" (the_t = : 't :> int)
=C2=A0 with
=C2=A0 | Invalid_argume= nt str -> Printf.printf "Error: %s" str

let () =3D test_conversions uint8 1 -> will work
..
let () =3D test_conversions uint64 =C2=A0(-1) -> will print Err= or...

Now this doesn't typecheck because the t= ype =C2=A0var 't in the signature is too general.
what I need= to put there is "a type coercible to int"
Is that poss= ible? Is there some way to achieve this?
Thanks in advance,
=
Immanuel
--001a11440e22595922051b9f7b5f--