okasaki

Okasaki's Purely Functional Data Structures
Log | Files | Refs | LICENSE

commit 0c3f691b03ab6c1b2cbeb40b2ba69d5b78e04ae4
parent 33e86fc085de0b27b3847b07e909e99115ea0fa5
Author: Jared Tobin <jared@jtobin.io>
Date:   Sat,  4 Mar 2023 23:14:01 +0400

Cosmetic tweaks.

Diffstat:
Mlib/Okasaki/Stack.hs | 13+++++++------
Mlib/Okasaki/Tree.hs | 1-
Mlib/Okasaki/Tree/CPS.hs | 4++--
3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/lib/Okasaki/Stack.hs b/lib/Okasaki/Stack.hs @@ -23,6 +23,7 @@ module Okasaki.Stack ( ) where import Prelude hiding (map) +import Data.Eq.Deriving (deriveEq1) import Data.Fix (Fix(..)) import Data.Functor.Foldable as RS import Text.Show.Deriving @@ -33,6 +34,7 @@ data StackF a r = deriving (Eq, Functor, Foldable, Traversable, Show) $(deriveShow1 ''StackF) +$(deriveEq1 ''StackF) type Stack a = Fix (StackF a) @@ -86,7 +88,7 @@ non s = case project s of cat :: Stack a -> Stack a -> Stack a cat l r = apo lag (project l) where lag = \case - NilF -> fmap Left (project r) + NilF -> fmap Left (project r) ConsF h t -> case project t of NilF -> ConsF h (Left r) rest -> ConsF h (Right rest) @@ -95,11 +97,10 @@ cat l r = apo lag (project l) where jab :: Int -> a -> Stack a -> Stack a jab n x s = apo lag (n, s) where lag (j, tac) = case project tac of - NilF -> NilF - ConsF h t -> - if j <= 0 - then ConsF x (Left t) - else ConsF h (Right (pred j, t)) + NilF -> NilF + ConsF h t + | j <= 0 -> ConsF x (Left t) + | otherwise -> ConsF h (Right (pred j, t)) -- exercise 2.1 diff --git a/lib/Okasaki/Tree.hs b/lib/Okasaki/Tree.hs @@ -20,7 +20,6 @@ module Okasaki.Tree ( import Data.Eq.Deriving (deriveEq1) import Data.Fix hiding (cata, ana, hylo) import Data.Functor.Foldable -import Data.Maybe (fromMaybe) import Data.Monoid import Okasaki.Orphans () import qualified Okasaki.Tree.CPS as CPS diff --git a/lib/Okasaki/Tree/CPS.hs b/lib/Okasaki/Tree/CPS.hs @@ -54,8 +54,8 @@ nod x l r = Fix (nodF x l r) sin :: a -> Tree a sin x = nod x lef lef -empty :: Tree a -> Bool -empty (project -> TreeF c) = c True b where +non :: Tree a -> Bool +non (project -> TreeF c) = c True b where b _ _ _ = False -- exercise 2.3 (no unnecessary copying) (?)