@@ -25,10 +25,7 @@ import Data.List.NonEmpty (NonEmpty(..))
25import qualified Data.List.NonEmpty as NEL
25import qualified Data.List.NonEmpty as NEL
26import qualified Data.Map.Strict as Map
26import qualified Data.Map.Strict as Map
27import Data.Maybe (fromMaybe)
27import Data.Maybe (fromMaybe)
28−import Data.Proxy (Proxy (..))
29−import Data.Typeable (TypeRep, Typeable, typeRep)
30import GHC.Generics(Generic)
28import GHC.Generics(Generic)
31−import qualified GHC.Generics as Generics
32import Data.Typeable (Typeable)
29import Data.Typeable (Typeable)
33import qualified Data.Dependent.Map as DM
30import qualified Data.Dependent.Map as DM
34import Data.Dependent.Map (DMap)
31import Data.Dependent.Map (DMap)
@@ -42,9 +39,6 @@ data Provenance
43class Breakdown x where
40class Breakdown x where
44 breakdown :: x -> NonEmpty Dynamic
41 breakdown :: x -> NonEmpty Dynamic
45−-- default breakdown :: Typeable x => x -> NonEmpty Dynamic
46−-- breakdown = pure . toDyn
49-- | Can't be built up from parts
43-- | Can't be built up from parts
50newtype Atom x = Atom { unAtom :: x }
44newtype Atom x = Atom { unAtom :: x }
@@ -55,15 +49,15 @@ newtype Compound x = Compound { unCompound :: x }
55-- | so, this is quite tricky. we need to witness the structure of `x`, but
49-- | so, this is quite tricky. we need to witness the structure of `x`, but
56-- we don't have an example of it yet. not entirely sure where to go.
50-- we don't have an example of it yet. not entirely sure where to go.
57instance (Typeable x, Generic x) => BuildFrom (Compound x) where
51instance (Typeable x, Generic x) => BuildFrom (Compound x) where
58− buildFrom stash = error "oops"
52+ buildFrom _stash = error "oops"
59-- breakdown = Map.fromListWith (<>) . fmap ((dynTypeRep &&& (\x -> NEL.fromList [x])) . toDyn . Generics.to) . _ . Generics.from
53-- breakdown = Map.fromListWith (<>) . fmap ((dynTypeRep &&& (\x -> NEL.fromList [x])) . toDyn . Generics.to) . _ . Generics.from
61−-- | this should be a bit more tractable.
55+-- -- | this should be a bit more tractable.
62−instance (Typeable x, Generic x) => Breakdown (Compound x) where
56+-- instance (Typeable x, Generic x) => Breakdown (Compound x) where
63− breakdown x = _ . Generics.from . unCompound $ x
57+-- breakdown x = _ . Generics.from . unCompound $ x
65instance Typeable x => BuildFrom (Atom x) where
59instance Typeable x => BuildFrom (Atom x) where
66− buildFrom = Map.lookup (typeRep (Proxy @x))
60+ buildFrom = DM.lookup R.typeRep . getStash
68newtype StashValue a = StashValue { getStashValue :: NonEmpty ([Provenance], a) }
62newtype StashValue a = StashValue { getStashValue :: NonEmpty ([Provenance], a) }
69 deriving (Functor, Show)
63 deriving (Functor, Show)
@@ -79,21 +73,11 @@ instance Show Stash where
80class Typeable x => BuildFrom (x :: Type) where
74class Typeable x => BuildFrom (x :: Type) where
81 buildFrom :: Stash -> Maybe (StashValue x)
75 buildFrom :: Stash -> Maybe (StashValue x)
82− default buildFrom :: Stash -> Maybe (StashValue x)
83− buildFrom = DM.lookup R.typeRep . getStash
85− -- (fmap promisedDyn . NEL.toList) . Map.lookup (typeRep (Proxy @x))
88−-- baseLookup :: TypeRep -> Stash -> Maybe (NonEmpty ([Provenance], Dynamic))
89−-- baseLookup tr mmm = -- Map.lookup (typeRep (Proxy @x)) mmm
92-- | only use this when we are using the internal typerep map.
77-- | only use this when we are using the internal typerep map.
93promisedDyn :: Typeable a => Dynamic -> a
78promisedDyn :: Typeable a => Dynamic -> a
94promisedDyn = fromMaybe (error "internal error, typerep map misconstructed") . fromDynamic
79promisedDyn = fromMaybe (error "internal error, typerep map misconstructed") . fromDynamic
96−-- instance BuildFrom Bool
97deriving via (Atom Bool) instance BuildFrom Bool
81deriving via (Atom Bool) instance BuildFrom Bool
99instance (Typeable x, BuildFrom x) => BuildFrom (Maybe x) where
83instance (Typeable x, BuildFrom x) => BuildFrom (Maybe x) where