caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Damien Doligez <damien.doligez@inria.fr>
To: caml-list <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] bizarre type
Date: Sun, 3 Jul 2005 13:42:20 +0200	[thread overview]
Message-ID: <d545e6e677699d1a8d6420206aeeac84@inria.fr> (raw)
In-Reply-To: <Pine.LNX.4.62.0506302337540.29747@hydrogene.pps.jussieu.fr>

On Jun 30, 2005, at 23:42, Julien Verlaguet wrote:

> In fact it prevents me from writting this :
>
> type 'a marshalled=string
>
> let make (x : 'a)=(Marshal.to_string x [] : 'a marshalled);;
>
> And then do all type of operations in a type safe way on strings.

If I understand correctly, this is your problem:

         Objective Caml version 3.08.3+4 (2005-06-21)

# type 'a marshalled=string;;
type 'a marshalled = string
# let make (x : 'a)=(Marshal.to_string x [] : 'a marshalled);;
val make : 'a -> 'a marshalled = <fun>
# make 1 = make "foo";; (* int marshalled is the same as string 
marshalled *)
- : bool = false

It works better you use a concrete type instead of an abbreviation:

# type 'a marsh2 = Marsh of string;;
type 'a marsh2 = Marsh of string
# let make2 (x : 'a) = (Marsh (Marshal.to_string x []) : 'a marsh2);;
val make2 : 'a -> 'a marsh2 = <fun>
# make2 1 = make2 "foo";; (* int marsh2 is not the same as string 
marsh2 *)
             ^^^^^^^^^^^
This expression has type string marsh2 but is here used with type int 
marsh2
#

-- Damien


  parent reply	other threads:[~2005-07-03 11:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-30 15:48 Julien Verlaguet
2005-06-30 16:49 ` [Caml-list] " Andreas Rossberg
2005-06-30 16:58   ` Julien Verlaguet
2005-06-30 17:16     ` Stephane Glondu
2005-06-30 17:24     ` Andreas Rossberg
2005-06-30 18:30   ` Julien Verlaguet
2005-06-30 19:37     ` Andreas Rossberg
2005-06-30 21:42       ` Julien Verlaguet
2005-06-30 23:57         ` Jacques Garrigue
2005-07-03 11:42         ` Damien Doligez [this message]
2005-07-03 12:37           ` Jacques Garrigue

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=d545e6e677699d1a8d6420206aeeac84@inria.fr \
    --to=damien.doligez@inria.fr \
    --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;
as well as URLs for NNTP newsgroup(s).