{-# Language PatternSynonyms, DeriveTraversable, TypeFamilies #-}
{-|
Module      : Toml.Semantics.Types
Description : Semantic TOML values
Copyright   : (c) Eric Mertens, 2023
License     : ISC
Maintainer  : emertens@gmail.com

This module provides the type for the semantics of a TOML file.
All dotted keys are resolved in this representation. Each table
is a Map with a single level of keys.

Values are parameterized over an annotation type to allow values
to be attributed to a file location. When values are constructed
programmatically, there might not be any interesting annotations.
In this case a trivial @()@ unit annotation can be used. The
'Value' type-synonym and related pattern synonyms can make using
this case more convenient.

-}
module Toml.Semantics.Types (
    -- * Unlocated value synonyms
    Value,
    Table,

    -- * Annotated values
    Value'(..,
        Integer, Double, Text, Bool,
        ZonedTime, Day, LocalTime, TimeOfDay,
        List, Table),
    Table'(..),

    -- * Utilities
    forgetValueAnns,
    forgetTableAnns,
    valueAnn,
    valueType,
    ) where

import Data.Map (Map)
import Data.String (IsString(fromString))
import Data.Text (Text)
import Data.Time (Day, LocalTime, TimeOfDay, ZonedTime(zonedTimeToLocalTime, zonedTimeZone), timeZoneMinutes)

pattern Integer :: Integer -> Value
pattern $mInteger :: forall {r}. Value -> (Integer -> r) -> ((# #) -> r) -> r
$bInteger :: Integer -> Value
Integer x <- Integer' _ x
    where Integer Integer
x = () -> Integer -> Value
forall a. a -> Integer -> Value' a
Integer' () Integer
x

pattern Double :: Double -> Value
pattern $mDouble :: forall {r}. Value -> (Double -> r) -> ((# #) -> r) -> r
$bDouble :: Double -> Value
Double x <- Double' _ x
    where Double Double
x = () -> Double -> Value
forall a. a -> Double -> Value' a
Double' () Double
x

pattern List :: [Value] -> Value
pattern $mList :: forall {r}. Value -> ([Value] -> r) -> ((# #) -> r) -> r
$bList :: [Value] -> Value
List x <- List' _ x
    where List [Value]
x = () -> [Value] -> Value
forall a. a -> [Value' a] -> Value' a
List' () [Value]
x

pattern Table :: Table -> Value
pattern $mTable :: forall {r}. Value -> (Table -> r) -> ((# #) -> r) -> r
$bTable :: Table -> Value
Table x <- Table' _ x
    where Table Table
x = () -> Table -> Value
forall a. a -> Table' a -> Value' a
Table' () Table
x

pattern Bool :: Bool -> Value
pattern $mBool :: forall {r}. Value -> (Bool -> r) -> ((# #) -> r) -> r
$bBool :: Bool -> Value
Bool x <- Bool' _ x
    where Bool Bool
x = () -> Bool -> Value
forall a. a -> Bool -> Value' a
Bool' () Bool
x

pattern Text :: Text -> Value
pattern $mText :: forall {r}. Value -> (Text -> r) -> ((# #) -> r) -> r
$bText :: Text -> Value
Text x <- Text' _ x
    where Text Text
x = () -> Text -> Value
forall a. a -> Text -> Value' a
Text' () Text
x

pattern TimeOfDay :: TimeOfDay -> Value
pattern $mTimeOfDay :: forall {r}. Value -> (TimeOfDay -> r) -> ((# #) -> r) -> r
$bTimeOfDay :: TimeOfDay -> Value
TimeOfDay x <- TimeOfDay' _ x
    where TimeOfDay TimeOfDay
x = () -> TimeOfDay -> Value
forall a. a -> TimeOfDay -> Value' a
TimeOfDay' () TimeOfDay
x

pattern ZonedTime :: ZonedTime -> Value
pattern $mZonedTime :: forall {r}. Value -> (ZonedTime -> r) -> ((# #) -> r) -> r
$bZonedTime :: ZonedTime -> Value
ZonedTime x <- ZonedTime' _ x
    where ZonedTime ZonedTime
x = () -> ZonedTime -> Value
forall a. a -> ZonedTime -> Value' a
ZonedTime' () ZonedTime
x

pattern LocalTime :: LocalTime -> Value
pattern $mLocalTime :: forall {r}. Value -> (LocalTime -> r) -> ((# #) -> r) -> r
$bLocalTime :: LocalTime -> Value
LocalTime x <- LocalTime' _ x
    where LocalTime LocalTime
x = () -> LocalTime -> Value
forall a. a -> LocalTime -> Value' a
LocalTime' () LocalTime
x

pattern Day :: Day -> Value
pattern $mDay :: forall {r}. Value -> (Day -> r) -> ((# #) -> r) -> r
$bDay :: Day -> Value
Day x <- Day' _ x
    where Day Day
x = () -> Day -> Value
forall a. a -> Day -> Value' a
Day' () Day
x

{-# Complete List, Table, Text, Bool, Integer, Double, Day, LocalTime, ZonedTime, TimeOfDay #-}

-- | Semantic TOML value with all table assignments resolved.
data Value' a
    = Integer'   a Integer
    | Double'    a Double
    | List'      a [Value' a]
    | Table'     a (Table' a)
    | Bool'      a Bool
    | Text'      a Text
    | TimeOfDay' a TimeOfDay
    | ZonedTime' a ZonedTime
    | LocalTime' a LocalTime
    | Day'       a Day
    deriving (
        Int -> Value' a -> ShowS
[Value' a] -> ShowS
Value' a -> String
(Int -> Value' a -> ShowS)
-> (Value' a -> String) -> ([Value' a] -> ShowS) -> Show (Value' a)
forall a. Show a => Int -> Value' a -> ShowS
forall a. Show a => [Value' a] -> ShowS
forall a. Show a => Value' a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Value' a -> ShowS
showsPrec :: Int -> Value' a -> ShowS
$cshow :: forall a. Show a => Value' a -> String
show :: Value' a -> String
$cshowList :: forall a. Show a => [Value' a] -> ShowS
showList :: [Value' a] -> ShowS
Show        {- ^ Default instance -},
        ReadPrec [Value' a]
ReadPrec (Value' a)
Int -> ReadS (Value' a)
ReadS [Value' a]
(Int -> ReadS (Value' a))
-> ReadS [Value' a]
-> ReadPrec (Value' a)
-> ReadPrec [Value' a]
-> Read (Value' a)
forall a. Read a => ReadPrec [Value' a]
forall a. Read a => ReadPrec (Value' a)
forall a. Read a => Int -> ReadS (Value' a)
forall a. Read a => ReadS [Value' a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Read a => Int -> ReadS (Value' a)
readsPrec :: Int -> ReadS (Value' a)
$creadList :: forall a. Read a => ReadS [Value' a]
readList :: ReadS [Value' a]
$creadPrec :: forall a. Read a => ReadPrec (Value' a)
readPrec :: ReadPrec (Value' a)
$creadListPrec :: forall a. Read a => ReadPrec [Value' a]
readListPrec :: ReadPrec [Value' a]
Read        {- ^ Default instance -},
        (forall a b. (a -> b) -> Value' a -> Value' b)
-> (forall a b. a -> Value' b -> Value' a) -> Functor Value'
forall a b. a -> Value' b -> Value' a
forall a b. (a -> b) -> Value' a -> Value' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Value' a -> Value' b
fmap :: forall a b. (a -> b) -> Value' a -> Value' b
$c<$ :: forall a b. a -> Value' b -> Value' a
<$ :: forall a b. a -> Value' b -> Value' a
Functor     {- ^ Derived          -},
        (forall m. Monoid m => Value' m -> m)
-> (forall m a. Monoid m => (a -> m) -> Value' a -> m)
-> (forall m a. Monoid m => (a -> m) -> Value' a -> m)
-> (forall a b. (a -> b -> b) -> b -> Value' a -> b)
-> (forall a b. (a -> b -> b) -> b -> Value' a -> b)
-> (forall b a. (b -> a -> b) -> b -> Value' a -> b)
-> (forall b a. (b -> a -> b) -> b -> Value' a -> b)
-> (forall a. (a -> a -> a) -> Value' a -> a)
-> (forall a. (a -> a -> a) -> Value' a -> a)
-> (forall a. Value' a -> [a])
-> (forall a. Value' a -> Bool)
-> (forall a. Value' a -> Int)
-> (forall a. Eq a => a -> Value' a -> Bool)
-> (forall a. Ord a => Value' a -> a)
-> (forall a. Ord a => Value' a -> a)
-> (forall a. Num a => Value' a -> a)
-> (forall a. Num a => Value' a -> a)
-> Foldable Value'
forall a. Eq a => a -> Value' a -> Bool
forall a. Num a => Value' a -> a
forall a. Ord a => Value' a -> a
forall m. Monoid m => Value' m -> m
forall a. Value' a -> Bool
forall a. Value' a -> Int
forall a. Value' a -> [a]
forall a. (a -> a -> a) -> Value' a -> a
forall m a. Monoid m => (a -> m) -> Value' a -> m
forall b a. (b -> a -> b) -> b -> Value' a -> b
forall a b. (a -> b -> b) -> b -> Value' a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => Value' m -> m
fold :: forall m. Monoid m => Value' m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Value' a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Value' a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Value' a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Value' a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> Value' a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Value' a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Value' a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Value' a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Value' a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Value' a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Value' a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Value' a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> Value' a -> a
foldr1 :: forall a. (a -> a -> a) -> Value' a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Value' a -> a
foldl1 :: forall a. (a -> a -> a) -> Value' a -> a
$ctoList :: forall a. Value' a -> [a]
toList :: forall a. Value' a -> [a]
$cnull :: forall a. Value' a -> Bool
null :: forall a. Value' a -> Bool
$clength :: forall a. Value' a -> Int
length :: forall a. Value' a -> Int
$celem :: forall a. Eq a => a -> Value' a -> Bool
elem :: forall a. Eq a => a -> Value' a -> Bool
$cmaximum :: forall a. Ord a => Value' a -> a
maximum :: forall a. Ord a => Value' a -> a
$cminimum :: forall a. Ord a => Value' a -> a
minimum :: forall a. Ord a => Value' a -> a
$csum :: forall a. Num a => Value' a -> a
sum :: forall a. Num a => Value' a -> a
$cproduct :: forall a. Num a => Value' a -> a
product :: forall a. Num a => Value' a -> a
Foldable    {- ^ Derived          -},
        Functor Value'
Foldable Value'
(Functor Value', Foldable Value') =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Value' a -> f (Value' b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Value' (f a) -> f (Value' a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Value' a -> m (Value' b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Value' (m a) -> m (Value' a))
-> Traversable Value'
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Value' (m a) -> m (Value' a)
forall (f :: * -> *) a.
Applicative f =>
Value' (f a) -> f (Value' a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Value' a -> m (Value' b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Value' a -> f (Value' b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Value' a -> f (Value' b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Value' a -> f (Value' b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Value' (f a) -> f (Value' a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Value' (f a) -> f (Value' a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Value' a -> m (Value' b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Value' a -> m (Value' b)
$csequence :: forall (m :: * -> *) a. Monad m => Value' (m a) -> m (Value' a)
sequence :: forall (m :: * -> *) a. Monad m => Value' (m a) -> m (Value' a)
Traversable {- ^ Derived          -})

-- | Extract the top-level annotation from a value.
valueAnn :: Value' a -> a
valueAnn :: forall a. Value' a -> a
valueAnn = \case
    Integer'   a
a Integer
_ -> a
a
    Double'    a
a Double
_ -> a
a
    List'      a
a [Value' a]
_ -> a
a
    Table'     a
a Table' a
_ -> a
a
    Bool'      a
a Bool
_ -> a
a
    Text'      a
a Text
_ -> a
a
    TimeOfDay' a
a TimeOfDay
_ -> a
a
    ZonedTime' a
a ZonedTime
_ -> a
a
    LocalTime' a
a LocalTime
_ -> a
a
    Day'       a
a Day
_ -> a
a

-- | String representation of the kind of value using TOML vocabulary
valueType :: Value' l -> String
valueType :: forall l. Value' l -> String
valueType = \case
    Integer'   {} -> String
"integer"
    Double'    {} -> String
"float"
    List'      {} -> String
"array"
    Table'     {} -> String
"table"
    Bool'      {} -> String
"boolean"
    Text'      {} -> String
"string"
    TimeOfDay' {} -> String
"local time"
    LocalTime' {} -> String
"local date-time"
    Day'       {} -> String
"locate date"
    ZonedTime' {} -> String
"offset date-time"

-- | A table with annotated keys and values.
newtype Table' a = MkTable (Map Text (a, Value' a))
    deriving (
        Int -> Table' a -> ShowS
[Table' a] -> ShowS
Table' a -> String
(Int -> Table' a -> ShowS)
-> (Table' a -> String) -> ([Table' a] -> ShowS) -> Show (Table' a)
forall a. Show a => Int -> Table' a -> ShowS
forall a. Show a => [Table' a] -> ShowS
forall a. Show a => Table' a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Table' a -> ShowS
showsPrec :: Int -> Table' a -> ShowS
$cshow :: forall a. Show a => Table' a -> String
show :: Table' a -> String
$cshowList :: forall a. Show a => [Table' a] -> ShowS
showList :: [Table' a] -> ShowS
Show        {- ^ Default instance -},
        ReadPrec [Table' a]
ReadPrec (Table' a)
Int -> ReadS (Table' a)
ReadS [Table' a]
(Int -> ReadS (Table' a))
-> ReadS [Table' a]
-> ReadPrec (Table' a)
-> ReadPrec [Table' a]
-> Read (Table' a)
forall a. Read a => ReadPrec [Table' a]
forall a. Read a => ReadPrec (Table' a)
forall a. Read a => Int -> ReadS (Table' a)
forall a. Read a => ReadS [Table' a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Read a => Int -> ReadS (Table' a)
readsPrec :: Int -> ReadS (Table' a)
$creadList :: forall a. Read a => ReadS [Table' a]
readList :: ReadS [Table' a]
$creadPrec :: forall a. Read a => ReadPrec (Table' a)
readPrec :: ReadPrec (Table' a)
$creadListPrec :: forall a. Read a => ReadPrec [Table' a]
readListPrec :: ReadPrec [Table' a]
Read        {- ^ Default instance -},
        Table' a -> Table' a -> Bool
(Table' a -> Table' a -> Bool)
-> (Table' a -> Table' a -> Bool) -> Eq (Table' a)
forall a. Eq a => Table' a -> Table' a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Table' a -> Table' a -> Bool
== :: Table' a -> Table' a -> Bool
$c/= :: forall a. Eq a => Table' a -> Table' a -> Bool
/= :: Table' a -> Table' a -> Bool
Eq          {- ^ Default instance -},
        (forall a b. (a -> b) -> Table' a -> Table' b)
-> (forall a b. a -> Table' b -> Table' a) -> Functor Table'
forall a b. a -> Table' b -> Table' a
forall a b. (a -> b) -> Table' a -> Table' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Table' a -> Table' b
fmap :: forall a b. (a -> b) -> Table' a -> Table' b
$c<$ :: forall a b. a -> Table' b -> Table' a
<$ :: forall a b. a -> Table' b -> Table' a
Functor     {- ^ Derived          -},
        (forall m. Monoid m => Table' m -> m)
-> (forall m a. Monoid m => (a -> m) -> Table' a -> m)
-> (forall m a. Monoid m => (a -> m) -> Table' a -> m)
-> (forall a b. (a -> b -> b) -> b -> Table' a -> b)
-> (forall a b. (a -> b -> b) -> b -> Table' a -> b)
-> (forall b a. (b -> a -> b) -> b -> Table' a -> b)
-> (forall b a. (b -> a -> b) -> b -> Table' a -> b)
-> (forall a. (a -> a -> a) -> Table' a -> a)
-> (forall a. (a -> a -> a) -> Table' a -> a)
-> (forall a. Table' a -> [a])
-> (forall a. Table' a -> Bool)
-> (forall a. Table' a -> Int)
-> (forall a. Eq a => a -> Table' a -> Bool)
-> (forall a. Ord a => Table' a -> a)
-> (forall a. Ord a => Table' a -> a)
-> (forall a. Num a => Table' a -> a)
-> (forall a. Num a => Table' a -> a)
-> Foldable Table'
forall a. Eq a => a -> Table' a -> Bool
forall a. Num a => Table' a -> a
forall a. Ord a => Table' a -> a
forall m. Monoid m => Table' m -> m
forall a. Table' a -> Bool
forall a. Table' a -> Int
forall a. Table' a -> [a]
forall a. (a -> a -> a) -> Table' a -> a
forall m a. Monoid m => (a -> m) -> Table' a -> m
forall b a. (b -> a -> b) -> b -> Table' a -> b
forall a b. (a -> b -> b) -> b -> Table' a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => Table' m -> m
fold :: forall m. Monoid m => Table' m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Table' a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Table' a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Table' a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Table' a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> Table' a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Table' a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Table' a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Table' a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Table' a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Table' a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Table' a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Table' a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> Table' a -> a
foldr1 :: forall a. (a -> a -> a) -> Table' a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Table' a -> a
foldl1 :: forall a. (a -> a -> a) -> Table' a -> a
$ctoList :: forall a. Table' a -> [a]
toList :: forall a. Table' a -> [a]
$cnull :: forall a. Table' a -> Bool
null :: forall a. Table' a -> Bool
$clength :: forall a. Table' a -> Int
length :: forall a. Table' a -> Int
$celem :: forall a. Eq a => a -> Table' a -> Bool
elem :: forall a. Eq a => a -> Table' a -> Bool
$cmaximum :: forall a. Ord a => Table' a -> a
maximum :: forall a. Ord a => Table' a -> a
$cminimum :: forall a. Ord a => Table' a -> a
minimum :: forall a. Ord a => Table' a -> a
$csum :: forall a. Num a => Table' a -> a
sum :: forall a. Num a => Table' a -> a
$cproduct :: forall a. Num a => Table' a -> a
product :: forall a. Num a => Table' a -> a
Foldable    {- ^ Derived          -},
        Functor Table'
Foldable Table'
(Functor Table', Foldable Table') =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Table' a -> f (Table' b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Table' (f a) -> f (Table' a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Table' a -> m (Table' b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Table' (m a) -> m (Table' a))
-> Traversable Table'
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Table' (m a) -> m (Table' a)
forall (f :: * -> *) a.
Applicative f =>
Table' (f a) -> f (Table' a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Table' a -> m (Table' b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Table' a -> f (Table' b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Table' a -> f (Table' b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Table' a -> f (Table' b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Table' (f a) -> f (Table' a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Table' (f a) -> f (Table' a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Table' a -> m (Table' b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Table' a -> m (Table' b)
$csequence :: forall (m :: * -> *) a. Monad m => Table' (m a) -> m (Table' a)
sequence :: forall (m :: * -> *) a. Monad m => Table' (m a) -> m (Table' a)
Traversable {- ^ Derived          -})

-- | A 'Table'' with trivial annotations
type Table = Table' ()

-- | A 'Value'' with trivial annotations
type Value = Value' ()

-- | Replaces annotations with a unit.
forgetTableAnns :: Table' a -> Table
forgetTableAnns :: forall a. Table' a -> Table
forgetTableAnns (MkTable Map Text (a, Value' a)
t) = Map Text ((), Value) -> Table
forall a. Map Text (a, Value' a) -> Table' a
MkTable (((a, Value' a) -> ((), Value))
-> Map Text (a, Value' a) -> Map Text ((), Value)
forall a b. (a -> b) -> Map Text a -> Map Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(a
_, Value' a
v) -> ((), Value' a -> Value
forall a. Value' a -> Value
forgetValueAnns Value' a
v)) Map Text (a, Value' a)
t)

-- | Replaces annotations with a unit.
forgetValueAnns :: Value' a -> Value
forgetValueAnns :: forall a. Value' a -> Value
forgetValueAnns =
    \case
        Integer'   a
_ Integer
x -> Integer -> Value
Integer   Integer
x
        Double'    a
_ Double
x -> Double -> Value
Double    Double
x
        List'      a
_ [Value' a]
x -> [Value] -> Value
List      ((Value' a -> Value) -> [Value' a] -> [Value]
forall a b. (a -> b) -> [a] -> [b]
map Value' a -> Value
forall a. Value' a -> Value
forgetValueAnns [Value' a]
x)
        Table'     a
_ Table' a
x -> Table -> Value
Table     (Table' a -> Table
forall a. Table' a -> Table
forgetTableAnns Table' a
x)
        Bool'      a
_ Bool
x -> Bool -> Value
Bool      Bool
x
        Text'      a
_ Text
x -> Text -> Value
Text      Text
x
        TimeOfDay' a
_ TimeOfDay
x -> TimeOfDay -> Value
TimeOfDay TimeOfDay
x
        ZonedTime' a
_ ZonedTime
x -> ZonedTime -> Value
ZonedTime ZonedTime
x
        LocalTime' a
_ LocalTime
x -> LocalTime -> Value
LocalTime LocalTime
x
        Day'       a
_ Day
x -> Day -> Value
Day       Day
x

-- | Nearly default instance except 'ZonedTime' doesn't have an
-- 'Eq' instance. 'ZonedTime' values are equal if their times and
-- time-zones are both equal.
instance Eq a => Eq (Value' a) where
    Integer'   a
a Integer
x == :: Value' a -> Value' a -> Bool
== Integer'   a
b Integer
y = a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
b Bool -> Bool -> Bool
&& Integer
x Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
y
    Double'    a
a Double
x == Double'    a
b Double
y = a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
b Bool -> Bool -> Bool
&& Double
x Double -> Double -> Bool
forall a. Eq a => a -> a -> Bool
== Double
y
    List'      a
a [Value' a]
x == List'      a
b [Value' a]
y = a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
b Bool -> Bool -> Bool
&& [Value' a]
x [Value' a] -> [Value' a] -> Bool
forall a. Eq a => a -> a -> Bool
== [Value' a]
y
    Table'     a
a Table' a
x == Table'     a
b Table' a
y = a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
b Bool -> Bool -> Bool
&& Table' a
x Table' a -> Table' a -> Bool
forall a. Eq a => a -> a -> Bool
== Table' a
y
    Bool'      a
a Bool
x == Bool'      a
b Bool
y = a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
b Bool -> Bool -> Bool
&& Bool
x Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
y
    Text'      a
a Text
x == Text'      a
b Text
y = a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
b Bool -> Bool -> Bool
&& Text
x Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
y
    TimeOfDay' a
a TimeOfDay
x == TimeOfDay' a
b TimeOfDay
y = a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
b Bool -> Bool -> Bool
&& TimeOfDay
x TimeOfDay -> TimeOfDay -> Bool
forall a. Eq a => a -> a -> Bool
== TimeOfDay
y
    LocalTime' a
a LocalTime
x == LocalTime' a
b LocalTime
y = a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
b Bool -> Bool -> Bool
&& LocalTime
x LocalTime -> LocalTime -> Bool
forall a. Eq a => a -> a -> Bool
== LocalTime
y
    Day'       a
a Day
x == Day'       a
b Day
y = a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
b Bool -> Bool -> Bool
&& Day
x Day -> Day -> Bool
forall a. Eq a => a -> a -> Bool
== Day
y
    ZonedTime' a
a ZonedTime
x == ZonedTime' a
b ZonedTime
y = a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
b Bool -> Bool -> Bool
&& ZonedTime -> (LocalTime, Int)
projectZT ZonedTime
x (LocalTime, Int) -> (LocalTime, Int) -> Bool
forall a. Eq a => a -> a -> Bool
== ZonedTime -> (LocalTime, Int)
projectZT ZonedTime
y
    Value' a
_              == Value' a
_              = Bool
False

-- Extract the relevant parts to build an 'Eq' instance
projectZT :: ZonedTime -> (LocalTime, Int)
projectZT :: ZonedTime -> (LocalTime, Int)
projectZT ZonedTime
x = (ZonedTime -> LocalTime
zonedTimeToLocalTime ZonedTime
x, TimeZone -> Int
timeZoneMinutes (ZonedTime -> TimeZone
zonedTimeZone ZonedTime
x))

-- | Constructs a TOML string literal.
--
-- @
-- fromString = String
-- @
instance () ~ a => IsString (Value' a) where
    fromString :: String -> Value' a
fromString = Text -> Value' a
Text -> Value
Text (Text -> Value' a) -> (String -> Text) -> String -> Value' a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
forall a. IsString a => String -> a
fromString