@@ -1,5 +1,8 @@
11{-# LANGUAGE DefaultSignatures #-}
22{-# LANGUAGE DerivingStrategies #-}
3+{-# LANGUAGE StandaloneDeriving #-}
4+{-# LANGUAGE DerivingVia #-}
5+
36
47module Roboservant.Types.Breakdown where
58
@@ -8,6 +11,7 @@ import Data.List.NonEmpty (NonEmpty (..))
811import qualified Data.List.NonEmpty as NEL
912import Data.Maybe (fromMaybe)
1013import Data.Typeable (Typeable)
14+import Roboservant.Types.Internal
1115
1216-- | only use this when we are using the internal typerep map.
1317promisedDyn :: Typeable a => Dynamic -> a
@@ -15,20 +19,15 @@ promisedDyn = fromMaybe (error "internal error, typerep map misconstructed") . f
1519
1620class Breakdown x where
1721 breakdown :: x -> NonEmpty Dynamic
18− default breakdown :: Typeable x => x -> NonEmpty Dynamic
19− breakdown = pure . toDyn
20−
21−-- | Can't break it down any further -- stuck in your teeth, maybe.
22−newtype Chewy x = Chewy {unChew :: x}
22+-- default breakdown :: Typeable x => x -> NonEmpty Dynamic
23+-- breakdown = pure . toDyn
2324
24−instance Breakdown () where
25− breakdown = pure . toDyn
2625
27−instance Breakdown Int where
28− breakdown = pure . toDyn
26+instance Typeable x => Breakdown (Atom x) where
27+ breakdown = pure . toDyn . unAtom
2928
30−instance Typeable x => Breakdown (Chewy x) where
31− breakdown x = pure (toDyn x)
29+deriving via (Atom ()) instance Breakdown ()
30+deriving via (Atom Int) instance Breakdown Int
3231
3332instance (Typeable a, Breakdown a) => Breakdown [a] where
3433 breakdown x = toDyn x :| mconcat (map (NEL.toList . breakdown) x)