模式匹配是最优雅的Haskell功能之一。Haskell中的模式匹配Seq's
我一直在一个项目最近,我需要一个队列数据结构,所以我使用Data.Sequence。然而,它看起来像我不得不放弃模式匹配的优雅和诉诸后卫:
floodFillWorker :: Image -> RGBAColor -> Double -> PixelQueue -> Image
floodFillWorker image base tolerance queue
| Seq.null queue = image
| otherwise = doSomeWork image
我能使用序列模式匹配或者我需要使用看守?
Thanks!我是否也可以使用它来为前面和其他模式匹配,如同列表一样? 例如 floodFillWorker _ _ _(first:rest)= .... – Bill 2010-01-16 17:31:14
我正在考虑指出这一点,但似乎OP实际上并不想在这里解构序列。但如果这有效,那么这很好。 – ephemient 2010-01-17 03:05:39
对不起,我原来的问题只有一半。谢谢澄清! – Bill 2010-01-17 04:34:09