packages feed

recollections-0.1.1.0: test/Spec.hs

{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -ddump-splices #-}

module Main (main) where

import Data.Recollections.TH
import Data.Foldable (toList)
import GHC.Generics
import Nested.Inner qualified as Inner
import Nested.Outer qualified as Outer

data Things
  = This
  | That
  | Something
  | Else
  | Entirely
  deriving (Eq, Ord, Show, Enum, Bounded, Generic)

mkCollection ''Things
mkIndices ''Things
mkDistribute ''Things
mkIndex ''Things
mkTabulate ''Things

main :: IO ()
main = do
  putStrLn $ "Applicative: " <>  show (pure @Collection ())
  putStrLn ""
  putStrLn $ "indices: " <>  show indices
  putStrLn ""
  putStrLn $ "indices, numeric: " <>  show (fmap fromEnum indices)
  putStrLn ""
  putStrLn $ "Representable.index: " <>  show ([ (t, t == index indices t) | t <- [minBound .. maxBound] ])
  putStrLn ""
  putStrLn $ "Representable.tabulate show: " <>  show (tabulate show)
  putStrLn ""
  putStrLn $ "Ditributive.distribute: " <>  show (distribute [indices])
  putStrLn ""
  putStrLn $ "Ditributive.collect: " <>  show (distribute . fmap (\thing -> pure $ thing == This) $ indices)
  putStrLn ""
  putStrLn $ "Nested indices: " <> show Outer.indices
  putStrLn ""
  putStrLn $ "Nested index roundtrip: " <> show (all (\t -> Outer.index Outer.indices t == t) Outer.indices)
  putStrLn ""
  putStrLn $ "Nested tabulate show: " <> show (Outer.tabulate show)
  putStrLn ""
  putStrLn $ "Nested distribute: " <> show (Outer.distribute [Outer.indices, Outer.indices])
  putStrLn ""
  putStrLn $ "Nested applicative: " <> show ((,) <$> Outer.indices <*> pure ())
  putStrLn ""
  putStrLn $ "Nested bounds: " <> show (minBound @Outer.Tag, maxBound @Outer.Tag)
  putStrLn ""
  putStrLn $ "Nested enum matches indices: " <> show ([minBound .. maxBound] == toList Outer.indices)
  putStrLn ""
  putStrLn $ "Nested fromEnum: " <> show (fmap fromEnum Outer.indices)
  putStrLn ""
  putStrLn $ "Nested toEnum roundtrip: " <> show (all (\t -> toEnum (fromEnum t) == t) Outer.indices)
  putStrLn ""
  putStrLn $ "Nested enumFromThen: " <> show [Outer.Front Inner.Bar, Outer.Local ..]