Again, thanks for all the assistance.
The warning and Match_failure in your post are what I expected in my program, but I didn't receive either. The print_samplerate function just returns the wrong answer. I tested it on 4.00.0 Win 32- and 64-bit, Linux 64-bit, and 4.01.0+dev6_2012-07-30 Linux 64-bit.
Even in the toplevel it runs fine:
# let print_samplerate : type id chan. (id,chan) frame_t -> unit = function
| {header_id = MPEG1; header_samplerate = S48000} -> Printf.printf "M1_S48000\n"
| {header_id = MPEG1; header_samplerate = S44100} -> Printf.printf "M1_S44100\n"
| {header_id = MPEG2; header_samplerate = S24000} -> Printf.printf "M2_S24000\n"
| {header_id = MPEG2; header_samplerate = S22050} -> Printf.printf "M2_S22050\n"
;;
val print_samplerate : ('id, 'chan) frame_t -> unit = <fun>
# let test_frame = frame_of_sr_id_chan (samplerate_of_int 3) (mpeg_of_int 0, channel_mode_of_int 0);;
val test_frame : (mpeg_tag_t, channel_tag_t) frame_t =
{header_id = MPEG1; header_crc = true; header_samplerate = S22050;
header_channel_mode = Channel_mono; side_bits = Bits_1_mono <abstr>}
# print_samplerate test_frame;;
M1_S44100
- : unit = ()
The exact file I ran is attached (hopefully -- are attachments good on this list?), and it prints "M1_S44100" with no errors or warnings on all my computers, even though I think it should give an exception or otherwise fail. Does it do something different on yours?
Thanks,
Reed
On Sat, Aug 4, 2012 at 4:45 PM, Gabriel Scherer
<gabriel.scherer@gmail.com> wrote:
> I was happy to notice that this did not complain about being
> incomplete, correctly seeing that the samplerates can only be used
> with a matching header_id;
>
> However, if I then I make an invalid frame using the *_of_int functions:
>
> let test_frame = frame_of_sr_id_chan (samplerate_of_int 3)
> (mpeg_of_int 0, channel_mode_of_int 0);;
> print_samplerate test_frame;;
Here is what I observe on my machine:
# let print_samplerate : type id chan. (id,chan) frame_t -> unit = function
[...]
Warning 8: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
{header_id=MPEG2; header_samplerate=S48000}
# let test_frame = frame_of_sr_id_chan (samplerate_of_int 3)
(mpeg_of_int 0, channel_mode_of_int 0);;
val test_frame : (mpeg_tag_t, channel_tag_t) frame_t =
{header_id = MPEG1; header_crc = true; header_samplerate = S22050;
header_channel_mode = Channel_mono; side_bits = Bits_1_mono <abstr>}
# print_samplerate test_frame;;
Exception: Match_failure ("//toplevel//", 43, -733).
--
ç