caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* List.cons and "::"
@ 2007-07-17 20:02 Sam Steingold
  2007-07-17 20:15 ` [Caml-list] " Brian Hurt
  2007-07-17 22:33 ` Jon Harrop
  0 siblings, 2 replies; 7+ messages in thread
From: Sam Steingold @ 2007-07-17 20:02 UTC (permalink / raw)
  To: caml-list

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Why is :: a syntax, not an infix version of List.cons
(which for some reason is missing)?
thanks.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGnSBVPp1Qsf2qnMcRAlJFAJ9V+FBi7yZOglQGIprGE0jTXGL5mwCfdn7y
0LCMZh14egRfCFG6Eu4aygQ=
=QvPw
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] List.cons and "::"
  2007-07-17 20:02 List.cons and "::" Sam Steingold
@ 2007-07-17 20:15 ` Brian Hurt
  2007-07-17 20:38   ` Martin Jambon
  2007-07-17 20:46   ` [Caml-list] " Chris King
  2007-07-17 22:33 ` Jon Harrop
  1 sibling, 2 replies; 7+ messages in thread
From: Brian Hurt @ 2007-07-17 20:15 UTC (permalink / raw)
  To: Sam Steingold; +Cc: caml-list

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.

Brian


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] List.cons and "::"
  2007-07-17 20:15 ` [Caml-list] " Brian Hurt
@ 2007-07-17 20:38   ` Martin Jambon
  2007-07-17 22:02     ` code17
  2007-07-17 20:46   ` [Caml-list] " Chris King
  1 sibling, 1 reply; 7+ messages in thread
From: Martin Jambon @ 2007-07-17 20:38 UTC (permalink / raw)
  To: Brian Hurt; +Cc: Sam Steingold, caml-list

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] List.cons and "::"
  2007-07-17 20:15 ` [Caml-list] " Brian Hurt
  2007-07-17 20:38   ` Martin Jambon
@ 2007-07-17 20:46   ` Chris King
  2007-07-18 21:36     ` Pierre Etchemaïté
  1 sibling, 1 reply; 7+ messages in thread
From: Chris King @ 2007-07-17 20:46 UTC (permalink / raw)
  To: Brian Hurt; +Cc: Sam Steingold, caml-list

On 7/17/07, Brian Hurt <bhurt@janestcapital.com> wrote:
> I wouldn't recommend it, but you could.
> :: and , you can't override.

Actually,

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

:)  This is because :: is considered a constructor, and not just
syntax (as is , or []).

But in general automatic currying of constructors would be nice (I
think Haskell does this).  There is probably some technical reason why
it's not a good idea in O'Caml though.

- Chris


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: List.cons and "::"
  2007-07-17 20:38   ` Martin Jambon
@ 2007-07-17 22:02     ` code17
  0 siblings, 0 replies; 7+ messages in thread
From: code17 @ 2007-07-17 22:02 UTC (permalink / raw)
  To: caml-list

Martin Jambon <martin.jambon@ens-lyon.org> writes:
> :: and () are just constructors with a special syntax.
... and so do "true" and "false".  

> You can override them:
... and the way of pattern matching (::) remains the same. 

[cf.] http://ocaml.cn/node/344


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] List.cons and "::"
  2007-07-17 20:02 List.cons and "::" Sam Steingold
  2007-07-17 20:15 ` [Caml-list] " Brian Hurt
@ 2007-07-17 22:33 ` Jon Harrop
  1 sibling, 0 replies; 7+ messages in thread
From: Jon Harrop @ 2007-07-17 22:33 UTC (permalink / raw)
  To: caml-list

On Tuesday 17 July 2007 21:02:29 Sam Steingold wrote:
> Why is :: a syntax, not an infix version of List.cons

List.cons would be a function whereas :: is a type constructor for the 'a list 
type:

# type 'a list = :: of 'a * 'a list;;
type 'a list = :: of 'a * 'a list
# let rec list = 1 :: list;;
val list : int list =
  :: (1, ...

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/?e


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] List.cons and "::"
  2007-07-17 20:46   ` [Caml-list] " Chris King
@ 2007-07-18 21:36     ` Pierre Etchemaïté
  0 siblings, 0 replies; 7+ messages in thread
From: Pierre Etchemaïté @ 2007-07-18 21:36 UTC (permalink / raw)
  To: caml-list

Le Tue, 17 Jul 2007 16:46:34 -0400, "Chris King" <colanderman@gmail.com> a écrit :

> But in general automatic currying of constructors would be nice (I
> think Haskell does this).  There is probably some technical reason why
> it's not a good idea in O'Caml though.

http://caml.inria.fr/pub/ml-archives/caml-list/2001/08/47db53a4b42529708647c9e81183598b.en.html


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-07-18 21:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-17 20:02 List.cons and "::" Sam Steingold
2007-07-17 20:15 ` [Caml-list] " Brian Hurt
2007-07-17 20:38   ` Martin Jambon
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

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).