我制作了一个简单的程序来处理我已经实现的队列数据结构。这是我的代码
transf :: Queue -> [Char]
transf emptyQueue = []
transf queue = [front queue] ++ transf (dequeue queue)
队列在哪里
newtype Queue = Q [Char] deriving (Show)
emptyQueue :: Queue
emptyQueue = Q []
queueIsEmpty :: Queue -> Bool
queueIsEmpty (Q []) = True
queueIsEmpty (Q _) = False
enqueue :: Char -> Queue -> Queue
enqueue x (Q q) = Q (q ++ [x])
dequeue :: Queue -> Queue
dequeue (Q (_:xs)) = Q xs
dequeue (Q []) = error "dequeue: empty queue"
front :: Queue -> Char
front (Q (x:_)) = x
front (Q []) = error "front: empty queue"
我的程序不会将队列转换为字符串。哪里有问题?提前致谢。