caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Martin Jambon <martin.jambon@ens-lyon.org>
To: Brian Hurt <bhurt@janestcapital.com>
Cc: Sam Steingold <sds@gnu.org>, caml-list@inria.fr
Subject: Re: [Caml-list] List.cons and "::"
Date: Tue, 17 Jul 2007 22:38:37 +0200 (CEST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0707172231360.18640@martin.ec.wink.com> (raw)
In-Reply-To: <469D235E.9000008@janestcapital.com>

On Tue, 17 Jul 2007, Brian Hurt wrote:

> Sam Steingold wrote:
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>> 
>> Why is :: a syntax, not an infix version of List.cons
>> (which for some reason is missing)?
>> thanks.
>> 
>> 
>
> So it can be used in pattern matching.  Things used in pattern matching the 
> compiler has to know about, and thus the user can't override.  Things not 
> used in pattern matching can be overridden.  So you can redefine + if you 
> wanted to.  I wouldn't recommend it, but you could. 
> : :  and , you can't override.

:: and () are just constructors with a special syntax.
You can override them:

         Objective Caml version 3.09.3

# type zarbi = :: of int * int | ();;
type zarbi = :: of int * int | ()
# ();;
- : zarbi = ()
# 1 :: 2;;
- : zarbi = :: (1, 2)


It's just that constructors are not automatically associated with a 
function, in OCaml.


Martin

--
http://martin.jambon.free.fr


  reply	other threads:[~2007-07-17 20:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-17 20:02 Sam Steingold
2007-07-17 20:15 ` [Caml-list] " Brian Hurt
2007-07-17 20:38   ` Martin Jambon [this message]
2007-07-17 22:02     ` code17
2007-07-17 20:46   ` [Caml-list] " Chris King
2007-07-18 21:36     ` Pierre Etchemaïté
2007-07-17 22:33 ` Jon Harrop

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=Pine.LNX.4.64.0707172231360.18640@martin.ec.wink.com \
    --to=martin.jambon@ens-lyon.org \
    --cc=bhurt@janestcapital.com \
    --cc=caml-list@inria.fr \
    --cc=sds@gnu.org \
    /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).