caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* specifying the type of an argument with more than one #classpath
@ 2008-03-06  1:52 Peng Zang
  2008-03-06  1:56 ` [Caml-list] " Edgar Friendly
  2008-03-06  2:16 ` Eric Cooper
  0 siblings, 2 replies; 5+ messages in thread
From: Peng Zang @ 2008-03-06  1:52 UTC (permalink / raw)
  To: caml-list

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

Hi,

I am aware that when specifying the type of an argument to a function, one can 
use the "#classpath" notation to specify "any subtype of classpath".

Eg:

class type foo = object
  method foo : string
end;;

# let takesomefoo (x:#foo) = x;;
val takesomefoo : (#foo as 'a) -> 'a = <fun>


However, I cannot figure out how to specify more than one such constraint.  
Eg. I want to specify an argument that is foo-able and bar-able like this:

class type bar = object
  method bar : string
end

# let takesomefooable_and_barable (x:#foo #bar) = x;;
The type constructor bar expects 0 argument(s),
but is here applied to 1 argument(s)


Which shows I'm clearly not syntactically expressing this correctly.  I 
checked the manual and it doesn't seem possible...  How do I do this or 
workaround it?  I am familiar with class definitions which allow you to do 
this:

class ['a] foobar (x:'a) = object
  constraint 'a = #foo
  constraint 'a = #bar
  method getx = x
end;;


But I don't see how to specify such constraints in a normal function on the 
type of an argument.

Is there some simple trick people have found for specifying various type 
constraints on arguments?


Thanks in advance,

Peng
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)

iD8DBQFHz05KfIRcEFL/JewRAjD4AJ9hexh+HUP5h2aavCbCXWR8JoVReQCePBBz
FIXqFDT3NEhLgtQZwrU7E54=
=qonr
-----END PGP SIGNATURE-----


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

* Re: [Caml-list] specifying the type of an argument with more than one #classpath
  2008-03-06  1:52 specifying the type of an argument with more than one #classpath Peng Zang
@ 2008-03-06  1:56 ` Edgar Friendly
  2008-03-06  2:04   ` Peng Zang
  2008-03-06  2:16 ` Eric Cooper
  1 sibling, 1 reply; 5+ messages in thread
From: Edgar Friendly @ 2008-03-06  1:56 UTC (permalink / raw)
  To: peng.zang; +Cc: caml-list

Peng Zang wrote:
> Is there some simple trick people have found for specifying various type 
> constraints on arguments?

How about something like:
let takesomefooable_and_barable x =
	ignore(lazy(x#foo));
	ignore(lazy(x#bar));
	x

E


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

* Re: [Caml-list] specifying the type of an argument with more than one #classpath
  2008-03-06  1:56 ` [Caml-list] " Edgar Friendly
@ 2008-03-06  2:04   ` Peng Zang
  0 siblings, 0 replies; 5+ messages in thread
From: Peng Zang @ 2008-03-06  2:04 UTC (permalink / raw)
  To: Edgar Friendly; +Cc: caml-list

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

This works if #foo just implies one method "foo".

But suppose it were more general, like:

  #drawable which implies methods draw2,drawfast,drawbuffered,etc..

and

  #foldable which implies methods iter,sample,map,to_list,etc...

We would like to avoid calling every implied method.


Thanks,

Peng


On Wednesday 05 March 2008 08:56:39 pm Edgar Friendly wrote:
> Peng Zang wrote:
> > Is there some simple trick people have found for specifying various type
> > constraints on arguments?
>
> How about something like:
> let takesomefooable_and_barable x =
> 	ignore(lazy(x#foo));
> 	ignore(lazy(x#bar));
> 	x
>
> E


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)

iD8DBQFHz1FEfIRcEFL/JewRAnlgAJ9kD4/itxfOvyl+IPIIaYojssHG+wCcDXIg
1CkxusK3dP96MHBS1PBe67k=
=2X1k
-----END PGP SIGNATURE-----


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

* Re: [Caml-list] specifying the type of an argument with more than one #classpath
  2008-03-06  1:52 specifying the type of an argument with more than one #classpath Peng Zang
  2008-03-06  1:56 ` [Caml-list] " Edgar Friendly
@ 2008-03-06  2:16 ` Eric Cooper
  2008-03-06 12:02   ` Peng Zang
  1 sibling, 1 reply; 5+ messages in thread
From: Eric Cooper @ 2008-03-06  2:16 UTC (permalink / raw)
  To: caml-list, caml-list

On Wed, Mar 05, 2008 at 08:52:06PM -0500, Peng Zang wrote:
> # let takesomefooable_and_barable (x:#foo #bar) = x;;
> The type constructor bar expects 0 argument(s),
> but is here applied to 1 argument(s)
> 
> 
> Which shows I'm clearly not syntactically expressing this correctly.  I 
> checked the manual and it doesn't seem possible...  How do I do this or 
> workaround it?

You were very close:

# let f ((x : #foo) : #bar) = x;; 
val f : (< bar : string; foo : string; .. > as 'a) -> 'a = <fun>

-- 
Eric Cooper             e c c @ c m u . e d u


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

* Re: [Caml-list] specifying the type of an argument with more than one #classpath
  2008-03-06  2:16 ` Eric Cooper
@ 2008-03-06 12:02   ` Peng Zang
  0 siblings, 0 replies; 5+ messages in thread
From: Peng Zang @ 2008-03-06 12:02 UTC (permalink / raw)
  To: caml-list; +Cc: Eric Cooper

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

Ahhh, perfect.  Caml-list at the rescue again.  Thanks Eric,

Peng

On Wednesday 05 March 2008 09:16:30 pm Eric Cooper wrote:
> On Wed, Mar 05, 2008 at 08:52:06PM -0500, Peng Zang wrote:
> > # let takesomefooable_and_barable (x:#foo #bar) = x;;
> > The type constructor bar expects 0 argument(s),
> > but is here applied to 1 argument(s)
> >
> >
> > Which shows I'm clearly not syntactically expressing this correctly.  I
> > checked the manual and it doesn't seem possible...  How do I do this or
> > workaround it?
>
> You were very close:
>
> # let f ((x : #foo) : #bar) = x;;
> val f : (< bar : string; foo : string; .. > as 'a) -> 'a = <fun>


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)

iD8DBQFHz91MfIRcEFL/JewRAjTdAKDAf1uJXdXf5+mdPIu5DGZ2TFUO1wCdH+qt
uksXC/TtmRAc8wqympEjCig=
=MfTR
-----END PGP SIGNATURE-----


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

end of thread, other threads:[~2008-03-06 12:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-06  1:52 specifying the type of an argument with more than one #classpath Peng Zang
2008-03-06  1:56 ` [Caml-list] " Edgar Friendly
2008-03-06  2:04   ` Peng Zang
2008-03-06  2:16 ` Eric Cooper
2008-03-06 12:02   ` Peng Zang

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