I am trying to create a heap module (and eventually priority queue) implemented with an array.
The portion of the heap I have written so far compiles fine:
module MinHeap = {
type elem
type heap = array<elem>
let make = (): heap => []
let insert = (h: heap, e: elem): heap => {
Belt.Array.push(h, e)->ignore
h
}
let next = (h: heap): option<elem> => Belt.Array.get(h, 0)
}
However I cannot instantiate it:
let h = MinHeap.make()
MinHeap.insert(h, 10)->ignore
The build fails with
FAILED: src/use-case-composites/heap-LogicParser.cmj
We've found a bug for you! /Users//projects//src/use-case-composites/heap.res:25:19-20
23 │
24 │ let h = MinHeap.make()
25 │ MinHeap.insert(h, 10)->ignore
26 │
This has type: int
Somewhere wanted: MinHeap.elem
There must be a away to pass types into modules. For example I am able to type option
, but how do you do that in a custom module?