caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Forget a type without Obj.magic
@ 2011-06-03  8:47 Dawid Toton
  0 siblings, 0 replies; only message in thread
From: Dawid Toton @ 2011-06-03  8:47 UTC (permalink / raw)
  To: caml-list

I have the following situation:

______
type 'a consumer = 'a -> unit

type 'a inactive = ('a consumer -> unit) list
type active

val activate : 'a consumer -> 'a inactive -> active

type bottom = unit

val forget_type : 'a inactive -> bottom inactive
______
let activate consumer inactive =
   let act inact = inact consumer in
   List.map act inactive

let bottom = ()

let forget_type inactive =
   let forget inact =
     (fun simple_consumer ->
        inact (fun _ -> simple_consumer bottom)
     )
    in
   (List.map forget inactive
   : unit inactive
   )
______

I see that the function forget_type above is a waste of time: it 
repackages functions that take () to functions that ignore the argument. 
But the simple_consumer already ignores the () argument, since there is 
no much use of it anyway.

My question is: how to change the above example, so that the forget_type 
becomes just a typecast (or maybe a constant time operation)?

I think that the type and value called bottom in the above code are 
currently not what I really want. Maybe even it should be called "top" 
instead? The argument of simple_consumer should have a type of "values 
impossible to use". How to express this?

Dawid

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-06-03  8:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-03  8:47 [Caml-list] Forget a type without Obj.magic Dawid Toton

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