{- |
Description: Supporting definitions for list problems
Copyright: Copyright (C) 2021 Yoo Chung
License: GPL-3.0-or-later
Maintainer: dev@chungyc.org

Supporting definitions for list problems.
-}
module Problems.Lists (NestedList (Elem, List), Encoding (Single, Multiple)) where

import           Control.DeepSeq
import           GHC.Generics    (Generic)

-- | A list type with arbitrary nesting of lists.
data NestedList a
  = Elem a              -- ^ A non-list element.
  | List [NestedList a] -- ^ Nested list.
  deriving (NestedList a -> NestedList a -> Bool
(NestedList a -> NestedList a -> Bool)
-> (NestedList a -> NestedList a -> Bool) -> Eq (NestedList a)
forall a. Eq a => NestedList a -> NestedList a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => NestedList a -> NestedList a -> Bool
== :: NestedList a -> NestedList a -> Bool
$c/= :: forall a. Eq a => NestedList a -> NestedList a -> Bool
/= :: NestedList a -> NestedList a -> Bool
Eq, Int -> NestedList a -> ShowS
[NestedList a] -> ShowS
NestedList a -> String
(Int -> NestedList a -> ShowS)
-> (NestedList a -> String)
-> ([NestedList a] -> ShowS)
-> Show (NestedList a)
forall a. Show a => Int -> NestedList a -> ShowS
forall a. Show a => [NestedList a] -> ShowS
forall a. Show a => NestedList a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> NestedList a -> ShowS
showsPrec :: Int -> NestedList a -> ShowS
$cshow :: forall a. Show a => NestedList a -> String
show :: NestedList a -> String
$cshowList :: forall a. Show a => [NestedList a] -> ShowS
showList :: [NestedList a] -> ShowS
Show, (forall x. NestedList a -> Rep (NestedList a) x)
-> (forall x. Rep (NestedList a) x -> NestedList a)
-> Generic (NestedList a)
forall x. Rep (NestedList a) x -> NestedList a
forall x. NestedList a -> Rep (NestedList a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (NestedList a) x -> NestedList a
forall a x. NestedList a -> Rep (NestedList a) x
$cfrom :: forall a x. NestedList a -> Rep (NestedList a) x
from :: forall x. NestedList a -> Rep (NestedList a) x
$cto :: forall a x. Rep (NestedList a) x -> NestedList a
to :: forall x. Rep (NestedList a) x -> NestedList a
Generic)

-- | Encodes one or more consecutively duplicate elements.
data Encoding a
  = Single a       -- ^ Represents a single occurrence of an element.
  | Multiple Int a -- ^ Represents an element repeating consecutively a given number of times.
  deriving (Encoding a -> Encoding a -> Bool
(Encoding a -> Encoding a -> Bool)
-> (Encoding a -> Encoding a -> Bool) -> Eq (Encoding a)
forall a. Eq a => Encoding a -> Encoding a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Encoding a -> Encoding a -> Bool
== :: Encoding a -> Encoding a -> Bool
$c/= :: forall a. Eq a => Encoding a -> Encoding a -> Bool
/= :: Encoding a -> Encoding a -> Bool
Eq, Int -> Encoding a -> ShowS
[Encoding a] -> ShowS
Encoding a -> String
(Int -> Encoding a -> ShowS)
-> (Encoding a -> String)
-> ([Encoding a] -> ShowS)
-> Show (Encoding a)
forall a. Show a => Int -> Encoding a -> ShowS
forall a. Show a => [Encoding a] -> ShowS
forall a. Show a => Encoding a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Encoding a -> ShowS
showsPrec :: Int -> Encoding a -> ShowS
$cshow :: forall a. Show a => Encoding a -> String
show :: Encoding a -> String
$cshowList :: forall a. Show a => [Encoding a] -> ShowS
showList :: [Encoding a] -> ShowS
Show, (forall x. Encoding a -> Rep (Encoding a) x)
-> (forall x. Rep (Encoding a) x -> Encoding a)
-> Generic (Encoding a)
forall x. Rep (Encoding a) x -> Encoding a
forall x. Encoding a -> Rep (Encoding a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Encoding a) x -> Encoding a
forall a x. Encoding a -> Rep (Encoding a) x
$cfrom :: forall a x. Encoding a -> Rep (Encoding a) x
from :: forall x. Encoding a -> Rep (Encoding a) x
$cto :: forall a x. Rep (Encoding a) x -> Encoding a
to :: forall x. Rep (Encoding a) x -> Encoding a
Generic, Encoding a -> ()
(Encoding a -> ()) -> NFData (Encoding a)
forall a. NFData a => Encoding a -> ()
forall a. (a -> ()) -> NFData a
$crnf :: forall a. NFData a => Encoding a -> ()
rnf :: Encoding a -> ()
NFData)