@@ -89,15 +89,17 @@ class AsSubtype sub sup where
8989 -- >>> duck ^? _Sub :: Maybe FourLeggedAnimal
9090 -- Nothing
9191 _Sub :: Prism' sup sub
92− _Sub = prism injectSub projectSub
92+ _Sub = prism injectSub (\i -> maybe (Left i) Right (projectSub i))
9393
9494 -- |Injects a subtype into a supertype (upcast).
9595 injectSub :: sub -> sup
96− injectSub = build (_Sub @sub @sup)
96+ injectSub
97+ = build (_Sub @sub @sup)
9798
9899 -- |Projects a subtype from a supertype (downcast).
99− projectSub :: sup -> Either sup sub
100− projectSub = match (_Sub @sub @sup)
100+ projectSub :: sup -> Maybe sub
101+ projectSub
102+ = either (const Nothing) Just . match (_Sub @sub @sup)
101103
102104 {-# MINIMAL (injectSub, projectSub) | _Sub #-}
103105