@@ -1,18 +1,15 @@
11{-# LANGUAGE AllowAmbiguousTypes #-}
22{-# LANGUAGE DataKinds #-}
3+{-# LANGUAGE DerivingVia #-}
4+{-# LANGUAGE StandaloneDeriving #-}
35{-# LANGUAGE DefaultSignatures #-}
46{-# LANGUAGE DerivingStrategies #-}
57{-# LANGUAGE FlexibleInstances #-}
68{-# LANGUAGE GADTs #-}
7−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
8−{-# LANGUAGE LambdaCase #-}
99{-# LANGUAGE PolyKinds #-}
1010{-# LANGUAGE ScopedTypeVariables #-}
11−{-# LANGUAGE StandaloneDeriving #-}
12−{-# LANGUAGE TupleSections #-}
1311{-# LANGUAGE TypeApplications #-}
1412{-# LANGUAGE TypeFamilies #-}
15−{-# LANGUAGE TypeOperators #-}
1613{-# LANGUAGE UndecidableInstances #-}
1714
1815module Roboservant.Types.Breakdown where
@@ -33,9 +30,17 @@ type Stash = Map TypeRep (NonEmpty ([Provenance], Dynamic))
3330
3431class Typeable x => BuildFrom x where
3532 buildFrom :: Stash -> Maybe (NonEmpty ([Provenance],Dynamic))
36− default buildFrom :: Stash -> Maybe (NonEmpty ([Provenance], Dynamic))
33+-- default buildFrom :: Stash -> Maybe (NonEmpty ([Provenance], Dynamic))
34+-- buildFrom = Map.lookup (typeRep (Proxy @x))
35+
36+
37+-- | Can't be built up from parts
38+newtype Atomic x = Atomic x
39+
40+instance Typeable x => BuildFrom (Atomic x) where
3741 buildFrom = Map.lookup (typeRep (Proxy @x))
3842
43+
3944 -- (fmap promisedDyn . NEL.toList) . Map.lookup (typeRep (Proxy @x))
4045
4146
@@ -47,7 +52,8 @@ class Typeable x => BuildFrom x where
4752promisedDyn :: Typeable a => Dynamic -> a
4853promisedDyn = fromMaybe (error "internal error, typerep map misconstructed") . fromDynamic
4954
50−instance BuildFrom Bool
55+-- instance BuildFrom Bool
56+deriving via (Atomic Bool) instance BuildFrom Bool
5157
5258instance (Typeable x, BuildFrom x) => BuildFrom (Maybe x) where
5359 buildFrom dict = Just $ fmap toDyn <$> options
@@ -58,22 +64,19 @@ instance (Typeable x, BuildFrom x) => BuildFrom (Maybe x) where
5864
5965class Breakdown x where
6066 breakdown :: x -> NonEmpty Dynamic
61− default breakdown :: Typeable x => x -> NonEmpty Dynamic
62− breakdown = pure . toDyn
63−
67+-- default breakdown :: Typeable x => x -> NonEmpty Dynamic
68+-- breakdown = pure . toDyn
69+
6470-- | Can't break it down any further -- stuck in your teeth, maybe.
6571newtype Chewy x = Chewy { unChew :: x }
6672
67−instance Breakdown () where
68− breakdown = pure . toDyn
73+instance Typeable a => Breakdown (Chewy a) where
74+ breakdown = pure . toDyn . unChew
6975
70−instance Breakdown Int where
71− breakdown = pure . toDyn
76+deriving via (Chewy ()) instance Breakdown ()
77+deriving via (Chewy Int) instance Breakdown Int
7278
7379
74−instance Typeable x => Breakdown (Chewy x) where
75− breakdown x = pure (toDyn x)
76−
7780--let d = toDyn x in Map.fromList [(dynTypeRep d, pure d)]
7881
7982-- instance (Typeable x, Generic x) => Breakdown x where
@@ -83,6 +86,6 @@ instance Typeable x => Breakdown (Chewy x) where
8386instance (Typeable a, Breakdown a) => Breakdown [a] where
8487 breakdown x = toDyn x :| mconcat (map (NEL.toList . breakdown) x)
8588
86−instance (BuildFrom a) => BuildFrom [a] -- where
87−-- breakdown x = toDyn x :| mconcat (map (NEL.toList . breakdown) x)
88−
89+instance (BuildFrom a) => BuildFrom [a] where
90+ buildFrom = error "fuuuck"
91+--- breakdown x = toDyn x :| mconcat (map (NEL.toList . breakdown) x)