okasaki

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

commit 7d73250a7772050b472f70d3072cc5efff53c93f
parent 5540bcc1f063c9f5379167bf048e26b3ceb9eef5
Author: Jared Tobin <jared@jtobin.ca>
Date:   Fri, 25 May 2018 11:53:12 +1200

Less fix.

Diffstat:
MStackRS.hs | 18+++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/StackRS.hs b/StackRS.hs @@ -29,9 +29,9 @@ push :: a -> Stack a -> Stack a push h t = Fix (ConsF h t) pop :: Stack a -> Maybe (a, Stack a) -pop s = case s of - Fix NilF -> Nothing - Fix (ConsF h t) -> Just (h, t) +pop s = case project s of + NilF -> Nothing + ConsF h t -> Just (h, t) fromList :: [a] -> Stack a fromList = ana coalg where @@ -41,14 +41,14 @@ fromList = ana coalg where toList :: Stack a -> [a] toList = ana coalg where - coalg = \case - Fix NilF -> Nil - Fix (ConsF h t) -> Cons h t + coalg s = case project s of + NilF -> Nil + ConsF h t -> Cons h t isEmpty :: Stack a -> Bool -isEmpty = \case - Fix NilF -> True - _ -> False +isEmpty s = case project s of + NilF -> True + _ -> False cat :: Stack a -> Stack a -> Stack a cat l r = apo coalg (project l) where