[wg-camlp4] getting bitstring to work with Core

Anil Madhavapeddy anil at recoil.org
Mon May 27 14:10:22 BST 2013


No, as you would have to re-open Core.Std in each of the pattern applications if you do it around the bitmatch.

-anil

On 27 May 2013, at 14:04, Gabriel Scherer <gabriel.scherer at gmail.com> wrote:

> Regarding your name-rebinding workaround, wouldn't it be enough to ask
> that any use of bitmatch..with be protected by an "let open Caml in"?
> 
> On Mon, May 27, 2013 at 12:47 PM, Anil Madhavapeddy <anil at recoil.org> wrote:
>> Core currently hides two functions needed by the Bitstring syntax extension: Char.code and String.unsafe_get.  I'm not sure what the best way to work around this is. Possibilities are:
>> 
>> - Core.Std.Caml has the original namespace from OCaml, so add a camlp4 flag to pa_bitstring to locally open Caml if the flag is specified.
>> 
>> - Add Char.code and String.unsafe_get to Core -- but there will be more similar incompatibilities lurking.
>> 
>> - Do nothing, and wait for the more explicit extension_points to show up.
>> 
>> - The below hack to get it to compile. Ugh.
>> 
>> --
>> open Core.Std
>> 
>> module Char = struct
>>  include Char
>>  let code = to_int
>> end
>> 
>> module String = struct
>>  include String
>>  let unsafe_get = Caml.String.unsafe_get
>> end
>> 
>> let show_gif_info filename () =
>>  let bits = Bitstring.bitstring_of_file filename in
>> 
>>  bitmatch bits with
>>  | { ("GIF87a"|"GIF89a") : 6*8 : string; (* GIF magic. *)
>>      width : 16 : littleendian;
>>      height : 16 : littleendian;
>>      colormap : 1;                     (* Has colormap? *)
>>      colorbits : 3;                    (* Color res = colorbits+1 *)
>>      sortflag : 1;
>>      bps : 3;                          (* Bits/pixel = bps+1 *)
>>      bg : 8;                           (* Background colour. *)
>>      aspectratio : 8 } ->
>>      printf "%s: GIF image:\n" filename;
>>      printf "  size %d %d\n" width height;
>>      printf "  has global colormap? %b\n" colormap;
>>      printf "  colorbits %d\n" (colorbits+1);
>>      printf "  global colormap is sorted? %b\n" sortflag;
>>      printf "  bits/pixel %d\n" (bps+1);
>>      printf "  background color index %d\n" bg;
>>      printf "  aspect ratio %d\n" aspectratio
>> 
>>  | { _ } ->
>>      eprintf "%s: Not a GIF image\n" filename
>> 
>> let () =
>>  Command.basic ~summary:"Display information about GIF file"
>>    Command.Spec.(
>>      empty +>
>>      anon ("filename" %: file)
>>    )
>>    show_gif_info
>>  |> Command.run
>> 
>> _______________________________________________
>> wg-camlp4 mailing list
>> wg-camlp4 at lists.ocaml.org
>> http://lists.ocaml.org/listinfo/wg-camlp4
> 
> -- 
> You received this message because you are subscribed to the Google Groups "ocaml-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ocaml-core+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 



More information about the wg-camlp4 mailing list