on develop help sign in
Add Functor superclass for FunctorMaybe; docs
commit61c22685d55104d0deb9c3b86223f84582eab9a0 authorLennart Spitzner <lsp@informatik.uni-kiel.de> dateMon 17 Oct 2016, 20:08 (10 years ago) parent59ca033
1 file changed+14−1
src/Reflex/Class.hs+14−1
src/Reflex/Class.hs+14−1
@@ -409,8 +409,21 @@ instance (Reflex t, Semigroup a) => Semigroup (Behavior t a) where
409409#endif
410410
411411--TODO: See if there's a better class in the standard libraries already
412+
412413-- | A class for values that combines filtering and mapping using 'Maybe'.
413−class FunctorMaybe f where
414+-- Morally, @'FunctorMaybe' ~ KleisliFunctor 'Maybe'@. Also similar is the
415+-- @Witherable@ typeclass, but it requires @Foldable f@ and @Traverable f@,
416+-- and e.g. 'Event' is instance of neither.
417+--
418+-- A definition of 'fmapMaybe' must satisfy the following laws:
419+--
420+-- [/identity/]
421+-- @'fmapMaybe' 'Just' ≡ 'id'@
422+--
423+-- [/composition/]
424+-- @'fmapMaybe' (f <=< g) ≡ 'fmapMaybe' f . 'fmapMaybe' g@
425+
426+class Functor f => FunctorMaybe f where
414427 -- | Combined mapping and filtering function.
415428 fmapMaybe :: (a -> Maybe b) -> f a -> f b
416429