caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] phantom types and identity function
@ 2012-11-27 11:00 Ivan Gotovchits
  2012-11-27 14:08 ` Jacques Garrigue
  0 siblings, 1 reply; 7+ messages in thread
From: Ivan Gotovchits @ 2012-11-27 11:00 UTC (permalink / raw)
  To: caml-list


Hello,

These simple signature 

   module type T = sig
       type 'a t constraint 'a = [< `A | `B ]
       val init: [`A] t
       val f: [`A] t -> [`B] t
   end

can be used to constrain the following module

   module T : T = struct
       type 'a t = unit constraint 'a = [< `A | `B]
       let init = ()
       let f x = x
   end

where identity function successfully satisfies the constraint

   [`A] t -> [`B] t

but in the following module 

   module T : T = struct
       type 'a t = {x:int} constraint 'a = [< `A | `B]
       let init = {x=0}
       let f x = x
   end

the same identity function doesn't satisfy.

I'll be genuinelly happy, if somebody clarify this issue for me :) My
guess is that the problem lies in the field of higher order polymorpism,
and instead the identity function with signature 'a -> 'a, a more
polymorphic function 'a -> 'b should be used. Though this contradicts
with the fact that the identity function works fine in the first
example and brings up another problem, which is how to obtain such
polymorphic function...

Thanks in advance!

-- 
         (__) 
         (oo) 
   /------\/ 
  / |    ||   
 *  /\---/\ 
    ~~   ~~   
...."Have you mooed today?"...

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

end of thread, other threads:[~2012-11-28 10:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-27 11:00 [Caml-list] phantom types and identity function Ivan Gotovchits
2012-11-27 14:08 ` Jacques Garrigue
2012-11-27 15:59   ` Gabriel Scherer
2012-11-28  3:42     ` Ivan Gotovchits
2012-11-28  8:12       ` Gabriel Scherer
2012-11-28 10:32         ` Ivan Gotovchits
2012-11-28  3:29   ` Ivan Gotovchits

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