<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Hello,<br><br>I've been trying to get enums/constant working and have been having a problem in matching types:<br><br>Error: This expression has type channel_states S.typ<br> but an expression was expected of type 'a Ctypes.typ = 'a Static.typ<br><br>I get the same error when I try the fruit example from ocaml-ctypes/tests/test-enums, although the issue may be due to a) my inexperience with ocaml and b) the way I generate the stubs. However, all of the c functions I'm mapping to compile without problems. This is essentially what I have:<br><br>bindings:<br>------------<br><br>open Ctypes<br><br>module Bindings<br> (F : sig type _ fn<br> val foreign : string -> ('a -> 'b) Ctypes.fn -> ('a -> 'b) fn end) (S : Cstubs.Types.TYPE) = struct<br> open F<br><br><br> type channel_states = ENDED | OPENING | OPEN<br><br> let ended = S.constant "ENDED" S.int64_t<br> let opening = S.constant "OPENING" S.int64_t<br> let open_ = S.constant "OPEN" S.int64_t<br><br> let channel_states = S.enum " channel_states" [<br> ENDED, ended;<br> OPENING, opening;<br> OPEN, open_;<br> ]<br><br> type channel_struct<br> let channel_struct = structure " channel_struct"<br> let (-:) ty label = field channel_struct label ty<br> let state = channel_states -: "state"<br> let capacity = uint32_t -: "capacity"<br> let () = seal (channel_struct : channel_struct structure typ)<br><br> type channel_t = channel_struct structure ptr<br> let channel_t = ptr channel_struct<br><br>... the error occurs at the state field at channel_states<br><br><br>the generator:<br>-------------------<br><br>open Channel_bindings<br><br>let c_headers = "#include \"/home/nick/channel/include/channel.h\""<br><br>let main () =<br> let ml_out = open_out "lib/channel_generated.ml" in<br> let c_out = open_out "lib/channel_stubs.c" in<br> let ml_fmt = Format.formatter_of_out_channel ml_out in<br> let c_fmt = Format.formatter_of_out_channel c_out in<br> Cstubs.write_ml ml_fmt ~prefix:"libchannel_" (module Bindings);<br> Format.fprintf c_fmt "%s@\n" c_headers;<br> Cstubs.write_c c_fmt ~prefix:"libchannel_" (module Bindings);<br> Format.pp_print_flush ml_fmt ();<br> Format.pp_print_flush c_fmt ();<br> close_out ml_out;<br> close_out c_out<br><br>let () =<br> main ()<br><br>and the oasis BuildDepends is : ctypes, ctypes.foreign, ctypes.stubs, ctypes.foreign.base, ctypes.foreign.unthreaded<br><br>I've been trying to work this out since early wednesday ( and learnt alot!) but I can't think of anything else to try. I've locally pinned ocaml-ctypes from github head.<br><br>Cheers<br>Nick<br> </div></body>
</html>