[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OCAML trouble

On Thu, Aug 4, 2011 at 4:04 PM, Eireann Leverett
<eireann.leverett@xxxxxxxxxx> wrote:
> Hi gurus,
> I am trying to construct a dnspacket; and I just can't seem to get the
> typing right for this detail record.
> The record structure looks like this inside dnspacket.ml:
> type detail = {
> Âqr: qr;
> Âopcode: opcode;
> Âaa: bool;
> Âtc: bool;
> Ârd: bool;
> Âra: bool;
> Ârcode: rcode;
> }
> So I am trying to construct one in my code like this:
> module DP = Dnspacket
> ...
> let d:DP.detail = {qr = `Query; opcode = `Query; aa = false; tc = false;
> rd = false; ra = true; rccode = `NoError;} in
> Â Â Â Âprint_endline (detail_to_string d);
> Which produces this error after the mir-unix-direct build:
> Error: Unbound record field label qr

The record type is in the namespace of DNSPacket (AKA DP). In order to
access the fields of this record you need to indicate this namespace.
It is done by prefixing the name of each filed with the module name,
like this :

let d:DP.detail = {DP.qr = `Query; DP.opcode = `Query; DP.aa = false;
DP.tc = false; DP.rd = false; DP.ra = true; DP.rccode = `NoError;} in
       print_endline (detail_to_string d);

If you find it too cumbersome, you can open the DP module locally or
use a syntax extension (whose name I don't remember).

> Now earlier I did an experiment to make sure qr had the right type, but
> printing our the qr_to_bool of q which worked fine. Somehow though however
> I massage it to produce the record I get an error. Can you help me Obi
> Wan?

May the namespace-aware-static-typing be with you.




Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.