{- |
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
forall a. Eq a => NestedList a -> NestedList a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NestedList a -> NestedList a -> Bool
$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
Eq, Int -> NestedList a -> ShowS
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
showList :: [NestedList a] -> ShowS
$cshowList :: forall a. Show a => [NestedList a] -> ShowS
show :: NestedList a -> String
$cshow :: forall a. Show a => NestedList a -> String
showsPrec :: Int -> NestedList a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> NestedList a -> ShowS
Show, 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
$cto :: forall a x. Rep (NestedList a) x -> NestedList a
$cfrom :: forall a x. NestedList a -> Rep (NestedList a) x
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
forall a. Eq a => Encoding a -> Encoding a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Encoding a -> Encoding a -> Bool
$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
Eq, Int -> Encoding a -> ShowS
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
showList :: [Encoding a] -> ShowS
$cshowList :: forall a. Show a => [Encoding a] -> ShowS
show :: Encoding a -> String
$cshow :: forall a. Show a => Encoding a -> String
showsPrec :: Int -> Encoding a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Encoding a -> ShowS
Show, 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
$cto :: forall a x. Rep (Encoding a) x -> Encoding a
$cfrom :: forall a x. Encoding a -> Rep (Encoding a) x
Generic, forall a. NFData a => Encoding a -> ()
forall a. (a -> ()) -> NFData a
rnf :: Encoding a -> ()
$crnf :: forall a. NFData a => Encoding a -> ()
NFData)