@@ -2,8 +2,8 @@
22{-# LANGUAGE DataKinds #-}
33{-# LANGUAGE DerivingVia #-}
44{-# LANGUAGE StandaloneDeriving #-}
5−{-# LANGUAGE DefaultSignatures #-}
6−{-# LANGUAGE DerivingStrategies #-}
5+
6+
77{-# LANGUAGE FlexibleInstances #-}
88{-# LANGUAGE GADTs #-}
99{-# LANGUAGE PolyKinds #-}
@@ -22,6 +22,7 @@ import Data.Map.Strict (Map)
2222import Data.Maybe (fromMaybe)
2323import Data.Proxy (Proxy (..))
2424import Data.Typeable (TypeRep, Typeable, typeRep)
25+import GHC.Generics(Generic)
2526
2627data Provenance
2728 = Provenance TypeRep Int
@@ -35,9 +36,18 @@ class Typeable x => BuildFrom x where
3536
3637
3738-- | Can't be built up from parts
38−newtype Atomic x = Atomic x
39+newtype Atom x = Atom { unAtom :: x }
40+
41+-- | can be broken down and built up from generic pieces
42+newtype Compound x = Compound { unCompound :: x }
3943
40−instance Typeable x => BuildFrom (Atomic x) where
44+instance (Typeable x, Generic x) => BuildFrom (Compound x) where
45+ buildFrom = error "buildfrom"
46+
47+instance (Typeable x, Generic x) => Breakdown (Compound x) where
48+ breakdown = error "breakdown"
49+
50+instance Typeable x => BuildFrom (Atom x) where
4151 buildFrom = Map.lookup (typeRep (Proxy @x))
4252
4353
@@ -53,13 +63,13 @@ promisedDyn :: Typeable a => Dynamic -> a
5363promisedDyn = fromMaybe (error "internal error, typerep map misconstructed") . fromDynamic
5464
5565-- instance BuildFrom Bool
56−deriving via (Atomic Bool) instance BuildFrom Bool
66+deriving via (Atom Bool) instance BuildFrom Bool
5767
5868instance (Typeable x, BuildFrom x) => BuildFrom (Maybe x) where
5969 buildFrom dict = Just $ fmap toDyn <$> options
6070 where options :: NonEmpty ([Provenance], Maybe x)
6171 options = ([],Nothing) :|
62− (maybe [] NEL.toList . fmap (fmap (fmap (Just . promisedDyn @x)))
72+ (maybe [] (NEL.toList . (fmap (fmap (Just . promisedDyn @x))))
6373 $ buildFrom @x dict)
6474
6575class Breakdown x where
@@ -67,14 +77,11 @@ class Breakdown x where
6777-- default breakdown :: Typeable x => x -> NonEmpty Dynamic
6878-- breakdown = pure . toDyn
6979
70−-- | Can't break it down any further -- stuck in your teeth, maybe.
71−newtype Chewy x = Chewy { unChew :: x }
72−
73−instance Typeable a => Breakdown (Chewy a) where
74− breakdown = pure . toDyn . unChew
80+instance Typeable a => Breakdown (Atom a) where
81+ breakdown = pure . toDyn . unAtom
7582
76−deriving via (Chewy ()) instance Breakdown ()
77−deriving via (Chewy Int) instance Breakdown Int
83+deriving via (Atom ()) instance Breakdown ()
84+deriving via (Atom Int) instance Breakdown Int
7885
7986
8087--let d = toDyn x in Map.fromList [(dynTypeRep d, pure d)]