Browse thread
Unexpected '_a problem
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2006-08-04 (02:42) |
From: | Jacques Garrigue <garrigue@m...> |
Subject: | Re: [Caml-list] Unexpected '_a problem |
From: "Chris King" <colanderman@gmail.com> > Okay, that (and Christophe's explanation) explains why hiding > everything in a module works. Thanks everyone for your help! It > seems I will have to use Obj.magic to get the type I want but at least > its use in this situation seems both safe and warranted. There are no "safe" uses of Obj.magic. It just happens to work in some cases, but it is strongly discouraged to use it to get around the type system, particularly when there are other ways to reach the same result. type 'a bar_t = Bar of <bar: ('a -> unit) -> unit> ;; let create_bar () = Bar (object method bar (_: 'a) = () end);; let b = create_bar ();; let Bar b = b;; Note that you need two definitions, as mixing the application with the extraction would loose the polymorphism. If you still want to use Obj.magic, remember to put complete type annotions on both its input and output, as the lack of type information may break the compiler. Jacques Garrigue