我正在尝试在F#中实现一个队列,目前这是我的代码,但我认为它的行为更像一个堆栈:
type 'a queue = NL| Que of 'a * 'a queue;;
let enque m = function
|NL -> Que(m, NL)
|Que(x, xs) -> Que(m, Que(x, xs));;
let rec peek = function
|NL -> failwith "queue is empty"
|Que(x, xs) -> x;;
let rec deque = function
|NL -> failwith "queue is empty"
|Que(x, xs) -> xs;;
let rec build = function
| [] -> NL
| x::xs -> enque x (build xs);;
除了enque操作之外,其他操作都正常运行。我想让它将新元素添加到队列后面而不是前面。