caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] shortcut to omit the functor keyword
@ 2011-03-25 18:43 Joel Reymont
  2011-03-25 19:10 ` Vincent Aravantinos
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Joel Reymont @ 2011-03-25 18:43 UTC (permalink / raw)
  To: caml-list

Why does the shortcut to omit the functor keyword only exists in module definitions but not in signatures?

For example, why do 

	module type A = sig end;;
	module type B = sig end;;

	module type C = functor (X : A) -> functor (Y : B) -> sig end;;

and not

	module type C (X : A) (Y : B) = sig end;;

the latter would be consistent with 

	module C (X : A) (Y : B) = struct end;;

--------------------------------------------------------------------------
- for hire: mac osx device driver ninja, kernel extensions and usb drivers
---------------------+------------+---------------------------------------
http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont
---------------------+------------+---------------------------------------





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

* Re: [Caml-list] shortcut to omit the functor keyword
  2011-03-25 18:43 [Caml-list] shortcut to omit the functor keyword Joel Reymont
@ 2011-03-25 19:10 ` Vincent Aravantinos
  2011-03-25 19:11 ` Andreas Rossberg
  2011-03-26  7:35 ` [Caml-list] " Satoshi Ogasawara
  2 siblings, 0 replies; 4+ messages in thread
From: Vincent Aravantinos @ 2011-03-25 19:10 UTC (permalink / raw)
  To: Joel Reymont; +Cc: caml-list

It seems to me as similar to the fact that you can write:

   type t = int -> int

but not:

   type t int = int

even though you can write:

   let f = fun x -> x + 1

or:

   let f x = x + 1

You're defining the type of a function, not a function over types.
Or, for modules:
You're defining the module type of a functor, not a functor over  
module types (not sure I could even call this a functor).

Le 25 mars 11 à 14:43, Joel Reymont a écrit :

> Why does the shortcut to omit the functor keyword only exists in  
> module definitions but not in signatures?
>
> For example, why do
>
> 	module type A = sig end;;
> 	module type B = sig end;;
>
> 	module type C = functor (X : A) -> functor (Y : B) -> sig end;;
>
> and not
>
> 	module type C (X : A) (Y : B) = sig end;;
>
> the latter would be consistent with
>
> 	module C (X : A) (Y : B) = struct end;;
>
> --------------------------------------------------------------------------
> - for hire: mac osx device driver ninja, kernel extensions and usb  
> drivers
> ---------------------+------------ 
> +---------------------------------------
> http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont
> ---------------------+------------ 
> +---------------------------------------
>
>
>
>
>
> -- 
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>



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

* Re: [Caml-list] shortcut to omit the functor keyword
  2011-03-25 18:43 [Caml-list] shortcut to omit the functor keyword Joel Reymont
  2011-03-25 19:10 ` Vincent Aravantinos
@ 2011-03-25 19:11 ` Andreas Rossberg
  2011-03-26  7:35 ` [Caml-list] " Satoshi Ogasawara
  2 siblings, 0 replies; 4+ messages in thread
From: Andreas Rossberg @ 2011-03-25 19:11 UTC (permalink / raw)
  To: Joel Reymont; +Cc: caml-list

On Mar 25, 2011, at 19.43 h, Joel Reymont wrote:
> Why does the shortcut to omit the functor keyword only exists in  
> module definitions but not in signatures?
>
> For example, why do
>
> 	module type A = sig end;;
> 	module type B = sig end;;
>
> 	module type C = functor (X : A) -> functor (Y : B) -> sig end;;
>
> and not
>
> 	module type C (X : A) (Y : B) = sig end;;

That syntax would suggest that C is a parameterized signature that you  
could use like

   module M : C(X)(Y)

But that's something entirely different from a functor signature.

> the latter would be consistent with
>
> 	module C (X : A) (Y : B) = struct end;;

No, it wouldn't - I'd say you are making a category error. It's easy  
to see in terms of core types and values, where the latter is  
analogous to

   let c x y = ...

while the former would be more like

   type ('a, 'b) c = ...

and *not* at all

   val c : 'a -> 'b -> ...

That is, a parameterized signature would correspond to a type  
constructor, while a functor signature corresponds to a function type.

Hope that helps,
/Andreas


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

* [Caml-list] Re: shortcut to omit the functor keyword
  2011-03-25 18:43 [Caml-list] shortcut to omit the functor keyword Joel Reymont
  2011-03-25 19:10 ` Vincent Aravantinos
  2011-03-25 19:11 ` Andreas Rossberg
@ 2011-03-26  7:35 ` Satoshi Ogasawara
  2 siblings, 0 replies; 4+ messages in thread
From: Satoshi Ogasawara @ 2011-03-26  7:35 UTC (permalink / raw)
  To: caml-list; +Cc: Joel Reymont

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

On 2011/03/26, at 3:43, Joel Reymont wrote:
> Why does the shortcut to omit the functor keyword only exists in module definitions but not in signatures?
> 
> For example, why do 
> 
> 	module type A = sig end;;
> 	module type B = sig end;;
> 
> 	module type C = functor (X : A) -> functor (Y : B) -> sig end;;
> 
> and not
> 
> 	module type C (X : A) (Y : B) = sig end;;

I'd like to suggest yet another grammar.

	module type C = functor (X : A) (Y : B) -> sig end;;

Here is a camlp4 code.

- ----
open Camlp4.PreCast

module Caml = Syntax

let expand_module_type_functor_args _loc args mt =
  List.fold_left 
    (fun mt (i, t) ->
       <:module_type< functor ( $i$ : $t$ ) -> $mt$ >>) mt (List.rev args)

EXTEND Caml.Gram
  GLOBAL: Caml.expr;
  Caml.str_item: LEVEL "top" [
    [ "module"; "type"; i = Caml.a_UIDENT; "="; "functor"; args = LIST1 functor_arg; "->"; mt = Caml.module_type ->
      <:str_item< module type $i$ = $expand_module_type_functor_args _loc args mt$ >>
    ]
  ];
  functor_arg : [
    [ "("; i = Caml.a_UIDENT; ":"; t = Caml.module_type; ")" -> 
       (i, t) 
    ]
  ];
END;;
- ----

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)

iEYEARECAAYFAk2Nl1cACgkQzTChtNfYLwa3lgCgl20db1FmDwhUyABil1eEAXj9
kVMAoPGI7ercFu6JX9t0Ev/bl3fWIvax
=a0Fh
-----END PGP SIGNATURE-----


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

end of thread, other threads:[~2011-03-26  7:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-25 18:43 [Caml-list] shortcut to omit the functor keyword Joel Reymont
2011-03-25 19:10 ` Vincent Aravantinos
2011-03-25 19:11 ` Andreas Rossberg
2011-03-26  7:35 ` [Caml-list] " Satoshi Ogasawara

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