2

私は説明された構造を持っています:

#define MAXVAL                   20 
#define ATOM_EL_LEN               6 
#define NUM_H_ISOTOPES            3 
typedef signed char   S_CHAR;
typedef unsigned char U_CHAR;
typedef signed short   S_SHORT;
typedef unsigned short U_SHORT;

typedef  S_SHORT AT_NUM;  

typedef struct tagInchiAtom {
    /* atom coordinates */
    double x;
    double y;
    double z;
    /* connectivity */
    AT_NUM  neighbor[MAXVAL];     /* adjacency list: ordering numbers of */
                                  /*            the adjacent atoms, >= 0 */
    S_CHAR  bond_type[MAXVAL];    /* inchi_BondType */
    /* 2D stereo */
    S_CHAR  bond_stereo[MAXVAL];  /* inchi_BondStereo2D; negative if the */
                                  /* sharp end points to opposite atom */
    /* other atom properties */
    char    elname[ATOM_EL_LEN];  /* zero-terminated chemical element name:*/
                                  /* "H", "Si", etc. */
    AT_NUM  num_bonds;            /* number of neighbors, bond types and bond*/
                                  /* stereo in the adjacency list */
    S_CHAR  num_iso_H[NUM_H_ISOTOPES+1]; /* implicit hydrogen atoms */
                                  /* [0]: number of implicit non-isotopic H
                                       (exception: num_iso_H[0]=-1 means INCHI
                                       adds implicit H automatically),
                                     [1]: number of implicit isotopic 1H (protium),
                                     [2]: number of implicit 2H (deuterium),
                                     [3]: number of implicit 3H (tritium) */
    AT_NUM  isotopic_mass;        /* 0 => non-isotopic; isotopic mass or  */
                                  /* ISOTOPIC_SHIFT_FLAG + mass - (average atomic mass) */
    S_CHAR  radical;              /* inchi_Radical */
    S_CHAR  charge;               /* positive or negative; 0 => no charge */
}inchi_Atom;

表すためinchi_Atomに、以下のデータ構造を作成しました。

type ConnGraph = [CShort]
data INCHIAtom = INCHIAtom {atoms :: ConnGraph,
                            label :: CString,
                            bondTypes :: ConnGraph,
                            charge :: CSChar}

Storable次に、この構造体のインスタンスを ( を使用してhsc2hs)実装しようとします。

instance Storable INCHIAtom where
    sizeOf    _ = (#size inchi_Atom)
    alignment _ = alignment (undefined :: CInt)
    peek _ = error "peek is not implemented"
    poke ptr (INCHIAtom atoms' label' bondType' charge') = do 
                                                          (#poke inchi_Atom, x) ptr $ (0 ::CDouble)
                                                          (#poke inchi_Atom, y) ptr $ (0 ::CDouble)
                                                          (#poke inchi_Atom, z) ptr $ (0 ::CDouble)
                                                          (#poke inchi_Atom, neighbor) ptr $ atoms'
                                                          (#poke inchi_Atom, bond_type) ptr $ bondType'
                                                          --(#poke inchi_Atom, bond_stereo) $ nullPtr
                                                          (#poke inchi_Atom, elname) ptr $ label'
                                                          (#poke inchi_Atom, num_bonds) ptr $ (length atoms')
                                                          (#poke inchi_Atom, num_iso_H) ptr $ (0 :: CSChar)
                                                          (#poke inchi_Atom, isotopic_mass) ptr $ (0 :: CShort)
                                                          (#poke inchi_Atom, radical) ptr $ (0 :: CSChar)
                                                          (#poke inchi_Atom, charge) ptr $ charge'

いくつか質問があります。Storableのインスタンスを実現する方法がありませんConnGraph。次に、 NULL ポインターを に置きたいのですbondStereoが、コメントを外す(#poke inchi_Atom, bond_stereo) $ nullPtrとコンパイル エラーが発生します。さらに、それalignment (undefined :: CInt)は私のデータ構造に合っていますか?

4

1 に答える 1