Version française
Home     About     Download     Resources     Contact us    
Browse thread
specifying the type of an argument with more than one #classpath
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Peng Zang <peng.zang@g...>
Subject: specifying the type of an argument with more than one #classpath
-----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-----