@@ -1,18 +1,15 @@
1{-# LANGUAGE AllowAmbiguousTypes #-}
1{-# LANGUAGE AllowAmbiguousTypes #-}
2{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DataKinds #-}
3+{-# LANGUAGE DerivingVia #-}
4+{-# LANGUAGE StandaloneDeriving #-}
3{-# LANGUAGE DefaultSignatures #-}
5{-# LANGUAGE DefaultSignatures #-}
4{-# LANGUAGE DerivingStrategies #-}
6{-# LANGUAGE DerivingStrategies #-}
5{-# LANGUAGE FlexibleInstances #-}
7{-# LANGUAGE FlexibleInstances #-}
6{-# LANGUAGE GADTs #-}
8{-# LANGUAGE GADTs #-}
7−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
8−{-# LANGUAGE LambdaCase #-}
9{-# LANGUAGE PolyKinds #-}
9{-# LANGUAGE PolyKinds #-}
10{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE ScopedTypeVariables #-}
11−{-# LANGUAGE StandaloneDeriving #-}
12−{-# LANGUAGE TupleSections #-}
13{-# LANGUAGE TypeApplications #-}
11{-# LANGUAGE TypeApplications #-}
14{-# LANGUAGE TypeFamilies #-}
12{-# LANGUAGE TypeFamilies #-}
15−{-# LANGUAGE TypeOperators #-}
16{-# LANGUAGE UndecidableInstances #-}
13{-# LANGUAGE UndecidableInstances #-}
18module Roboservant.Types.Breakdown where
15module Roboservant.Types.Breakdown where
@@ -33,9 +30,17 @@ type Stash = Map TypeRep (NonEmpty ([Provenance], Dynamic))
34class Typeable x => BuildFrom x where
31class Typeable x => BuildFrom x where
35 buildFrom :: Stash -> Maybe (NonEmpty ([Provenance],Dynamic))
32 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))
37+-- | Can't be built up from parts
38+newtype Atomic x = Atomic x
40+instance Typeable x => BuildFrom (Atomic x) where
37 buildFrom = Map.lookup (typeRep (Proxy @x))
41 buildFrom = Map.lookup (typeRep (Proxy @x))
39 -- (fmap promisedDyn . NEL.toList) . Map.lookup (typeRep (Proxy @x))
44 -- (fmap promisedDyn . NEL.toList) . Map.lookup (typeRep (Proxy @x))
@@ -47,7 +52,8 @@ class Typeable x => BuildFrom x where
47promisedDyn :: Typeable a => Dynamic -> a
52promisedDyn :: Typeable a => Dynamic -> a
48promisedDyn = fromMaybe (error "internal error, typerep map misconstructed") . fromDynamic
53promisedDyn = fromMaybe (error "internal error, typerep map misconstructed") . fromDynamic
55+-- instance BuildFrom Bool
50−instance BuildFrom Bool
56+deriving via (Atomic Bool) instance BuildFrom Bool
52instance (Typeable x, BuildFrom x) => BuildFrom (Maybe x) where
58instance (Typeable x, BuildFrom x) => BuildFrom (Maybe x) where
53 buildFrom dict = Just $ fmap toDyn <$> options
59 buildFrom dict = Just $ fmap toDyn <$> options
@@ -58,22 +64,19 @@ instance (Typeable x, BuildFrom x) => BuildFrom (Maybe x) where
59class Breakdown x where
65class Breakdown x where
60 breakdown :: x -> NonEmpty Dynamic
66 breakdown :: x -> NonEmpty Dynamic
61− default breakdown :: Typeable x => x -> NonEmpty Dynamic
67+-- default breakdown :: Typeable x => x -> NonEmpty Dynamic
62− breakdown = pure . toDyn
68+-- breakdown = pure . toDyn
64-- | Can't break it down any further -- stuck in your teeth, maybe.
70-- | Can't break it down any further -- stuck in your teeth, maybe.
65newtype Chewy x = Chewy { unChew :: x }
71newtype Chewy x = Chewy { unChew :: x }
67−instance Breakdown () where
73+instance Typeable a => Breakdown (Chewy a) where
68− breakdown = pure . toDyn
74+ breakdown = pure . toDyn . unChew
70−instance Breakdown Int where
76+deriving via (Chewy ()) instance Breakdown ()
71− breakdown = pure . toDyn
77+deriving via (Chewy Int) instance Breakdown Int
74−instance Typeable x => Breakdown (Chewy x) where
75− breakdown x = pure (toDyn x)
77--let d = toDyn x in Map.fromList [(dynTypeRep d, pure d)]
80--let d = toDyn x in Map.fromList [(dynTypeRep d, pure d)]
79-- instance (Typeable x, Generic x) => Breakdown x where
82-- instance (Typeable x, Generic x) => Breakdown x where
@@ -83,6 +86,6 @@ instance Typeable x => Breakdown (Chewy x) where
83instance (Typeable a, Breakdown a) => Breakdown [a] where
86instance (Typeable a, Breakdown a) => Breakdown [a] where
84 breakdown x = toDyn x :| mconcat (map (NEL.toList . breakdown) x)
87 breakdown x = toDyn x :| mconcat (map (NEL.toList . breakdown) x)
86−instance (BuildFrom a) => BuildFrom [a] -- where
89+instance (BuildFrom a) => BuildFrom [a] where
90+ buildFrom = error "fuuuck"
87−-- breakdown x = toDyn x :| mconcat (map (NEL.toList . breakdown) x)
91+--- breakdown x = toDyn x :| mconcat (map (NEL.toList . breakdown) x)