Come faccio a creare un tipo che utilizza Dyn_array di Batteries in OCaml?

StackOverflow https://stackoverflow.com/questions/1813020

  •  06-07-2019
  •  | 
  •  

Domanda

Ad esempio, supponiamo di voler creare un tipo come questo (usando Dyn_array ):

type some_type = SomeConstructor of <Dyn_array of integers>

Però mi sento un po 'perso su come farlo. Qualcuno potrebbe darmi un esempio in modo da potermi avvolgere la testa?

È stato utile?

Soluzione

Qual è il problema? la sintassi?

Hai provato a usare un tipo intermedio?

type my_dyn = Dyn_Array of int

type some_type = SomeConstructor of my_dyn

Altri suggerimenti

(Non ho batterie installate). DynArray.t è già definito. Vuoi solo specificare il tipo per la sua variabile libera e non definire un nuovo costruttore (cosa farebbe X of y , beh, a parte il fatto che quella sintassi incorporata è illegale),

type some_type = SomeConstructor of integers DynArray.t

Se si desidera lasciare libero il tipo di DynArray,

type 'a some_type = SomeConstructor of 'a DynArray.t
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top