Attempt:
let symbol_table = Array.make 256 Stack.create()
However, I don't specify the type of the stack when creating the array, so I want to know how you would do this by specifying the type of the stack.
You should use Array.init to create an array of different stack instances
Array.init 256 (fun _ -> Stack.create ())
If you will do Array.make 256 (Stack.create ())
then you will create one instance of a stack, and assign it to each element of the array. Thus Stack.push 4 symbol_table.(0)
will push a symbol into all 256 stacks.
See also a relevant answer.
The type will be inferred when you use it:
let symbol_table = Array.make 256 (Stack.create ())
let () = Stack.push 4 symbol_table.(0)
But you can also specify the type on the let binding, if you need to:
let symbol_table : int Stack.t array = Array.make 256 (Stack.create ())
Edit: As noted in the comments you should be using Array.init
to initialize the array with 256 separate instances, rather than the 256 references to the same stack instance you'd get with Array.make
:
let symbol_table : int Stack.t array = Array.init 256 (fun _ -> Stack.create ())