From 1c169b45bff5782232f29879df466bb4c8ba31f2 Mon Sep 17 00:00:00 2001 From: Cyril Sobierajewicz Date: Sun, 20 Dec 2020 17:26:43 +0100 Subject: [PATCH 1/2] Idiomatic Show instance for lazy lists --- src/Data/List/Lazy/Types.purs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Data/List/Lazy/Types.purs b/src/Data/List/Lazy/Types.purs index 5dbf82c..fb70501 100644 --- a/src/Data/List/Lazy/Types.purs +++ b/src/Data/List/Lazy/Types.purs @@ -34,6 +34,10 @@ newtype List a = List (Lazy (Step a)) -- | `Cons` constructor). data Step a = Nil | Cons a (List a) +instance showStep :: Show a => Show (Step a) where + show Nil = "Nil" + show (Cons x xs) = "(" <> show x <> " : " <> show xs <> ")" + -- | Unwrap a lazy linked list step :: forall a. List a -> Step a step = force <<< unwrap @@ -59,10 +63,12 @@ infixr 6 cons as : derive instance newtypeList :: Newtype (List a) _ instance showList :: Show a => Show (List a) where - show xs = "fromStrict (" <> go (step xs) <> ")" - where - go Nil = "Nil" - go (Cons x xs') = "(Cons " <> show x <> " " <> go (step xs') <> ")" + show xs = "(fromFoldable [" + <> case step xs of + Nil -> "" + Cons x xs' -> + show x <> foldl (\shown x' -> shown <> "," <> show x') "" xs' + <> "])" instance eqList :: Eq a => Eq (List a) where eq = eq1 From acfae4fa5acbf79d077d24a6dacd986b00cb5ce4 Mon Sep 17 00:00:00 2001 From: Cyril Sobierajewicz Date: Sat, 30 Jan 2021 17:09:18 +0100 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f1270f..9853cef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Breaking changes: - Renamed `scanrLazy` to `scanlLazy` and fixed parameter ordering (#161) - Renamed `group'` to `groupAll` (#182) - Changed `Alt ZipList` to satisfy distributivity (#150) +- Updated the `Show` instances for (non empty) lazy lists (#181) New features: - Added `nubEq`/`nubByEq` (#179)