好的,所以我想用箭头来找点乐子。我试图直接将性感的 Haskell 快速排序转换为使用箭头的实现。但它不能正常工作。
import Control.Arrow
qs :: Ord a => [a] -> [a]
qs = isEmpty >>> right (head &&& tail
>>> first ((qs.) . filter . (<)
&&& (\x -> (x:) . qs . filter (>=x)))
>>> first (uncurry (&&&))
>>> uncurry id
>>> uncurry (++))
>>> extract
where
isEmpty [] = Left []
isEmpty x = Right x
extract (Left x) = x
extract (Right x) = x
有人能发现问题吗?