caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* class type param constraint
@ 2009-04-09  8:42 Radzevich Belevich
  2009-04-09 10:10 ` [Caml-list] " Radzevich Belevich
  2009-04-09 10:13 ` Jacques Garrigue
  0 siblings, 2 replies; 4+ messages in thread
From: Radzevich Belevich @ 2009-04-09  8:42 UTC (permalink / raw)
  To: Caml List

class [ 'c ] a = 
  object(self)                  
    constraint 'c = < .. >
    method as_c =  (self :> 'c)
    method id = Oo.id self
  end          ;;
class ['a] a :
  object ('a)
    constraint 'a = < as_c : 'a; id : int; .. >
    method as_c : 'a
    method id : int
  end
================

Why type 'c must have methods "as_c" and "id" ? 



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

* Re: [Caml-list] class type param constraint
  2009-04-09  8:42 class type param constraint Radzevich Belevich
@ 2009-04-09 10:10 ` Radzevich Belevich
  2009-04-09 10:13 ` Jacques Garrigue
  1 sibling, 0 replies; 4+ messages in thread
From: Radzevich Belevich @ 2009-04-09 10:10 UTC (permalink / raw)
  To: Caml List

In previous message poorly worded question.
Why 'c should include "a". ":>" cast, 'c should be smaller type, but not
great



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

* Re: [Caml-list] class type param constraint
  2009-04-09  8:42 class type param constraint Radzevich Belevich
  2009-04-09 10:10 ` [Caml-list] " Radzevich Belevich
@ 2009-04-09 10:13 ` Jacques Garrigue
  2009-04-09 10:21   ` Radzevich Belevich
  1 sibling, 1 reply; 4+ messages in thread
From: Jacques Garrigue @ 2009-04-09 10:13 UTC (permalink / raw)
  To: radzevich.belevich; +Cc: caml-list

From: Radzevich Belevich <radzevich.belevich@gmail.com>
> class [ 'c ] a = 
>   object(self)                  
>     constraint 'c = < .. >
>     method as_c =  (self :> 'c)
>     method id = Oo.id self
>   end          ;;
> class ['a] a :
>   object ('a)
>     constraint 'a = < as_c : 'a; id : int; .. >
>     method as_c : 'a
>     method id : int
>   end
> ================
> 
> Why type 'c must have methods "as_c" and "id" ? 

This may be a bit confusing, but the .. in your constraint on 'c means
that no actual subtyping will occur when you use this type as target.
Indeed, if the constraint was left unchanged, it would mean that by
choosing an arbitrary instance, you could use the as_c method to
convert an object of type "t a" to any "t".
Since no subtyping occurs, (self :> 'c) is just equivalent to
(self : 'c) (i.e. unify 'c with the type of self).
As a result, you get
  object ('a)
    ...
    method as_c : 'a
    ...
  end

Jacques


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

* Re: [Caml-list] class type param constraint
  2009-04-09 10:13 ` Jacques Garrigue
@ 2009-04-09 10:21   ` Radzevich Belevich
  0 siblings, 0 replies; 4+ messages in thread
From: Radzevich Belevich @ 2009-04-09 10:21 UTC (permalink / raw)
  To: Jacques Garrigue; +Cc: caml-list

On Thu, 2009-04-09 at 19:13 +0900, Jacques Garrigue wrote:
> This may be a bit confusing, but the .. in your constraint on 'c means
> that no actual subtyping will occur when you use this type as target.
> Indeed, if the constraint was left unchanged, it would mean that by
> choosing an arbitrary instance, you could use the as_c method to
> convert an object of type "t a" to any "t".
Why it can't be converted to any valid "t"?


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

end of thread, other threads:[~2009-04-09 10:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-09  8:42 class type param constraint Radzevich Belevich
2009-04-09 10:10 ` [Caml-list] " Radzevich Belevich
2009-04-09 10:13 ` Jacques Garrigue
2009-04-09 10:21   ` Radzevich Belevich

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