[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Martin Jambon <martin.jambon@e...> |
| Subject: | Re: [Caml-list] List.cons and "::" |
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