Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
-- Loengus toodud näite - remUntilLast - variatsioonid Haskellis -- by Härmel Nestra remUntilLast0 p --lihtne = reverse . takeWhile (not . p) . reverse remUntilLast1 p --akumulaatoriga = let e = reverse op x c = c . if p x then const [] else (x :) in flip (foldr op e) [] -- ^^akumulaator remUntilLast2 p --jätkuga = let e = ($ []) op x f = f . if p x then const id else \c -> c . (x :) in flip (foldr op e) id -- ^^jätk --Kerge on tähele panna remUntilLast1 ja remUntilLast2 üldskeemi --sarnasust. --abstractRem :: a -> (b -> a -> a) -> (a -> c) -> (b -> Bool) -> [b] -> c abstractRem begin save end p = flip (foldr (\x f -> f . if p x then const begin else save x) end) begin remUntilLast1' = abstractRem [] (:) reverse --akumulaatoriga remUntilLast2' = abstractRem id (\x c -> c . (x :)) ($ []) --jätkuga -- remUntilLast1' ja remUntilLast2' ajakeerukuste erinevus --on O(1), mälukeerukuste erinevus aga O(tulemuslisti pikkus). Seejuures -- remUntilLast1' võtab pisut vähem aega, remUntilLast2' aga vähem mälu. --Seejuures remUntilLast2' kannatab välja tunduvalt pikemaid tulemusliste.