|
| 1 | +{-# LANGUAGE CPP #-} |
| 2 | +{-# LANGUAGE DeriveTraversable #-} |
| 3 | +{-# LANGUAGE DerivingVia #-} |
| 4 | +{-# LANGUAGE StandaloneDeriving #-} |
| 5 | +{- | |
| 6 | +FIXME some inspiration/guidance needed here |
| 7 | +-} |
| 8 | +module Control.Selective.Trans.Validation where |
| 9 | + |
| 10 | +import Data.Functor.Compose |
| 11 | +#if MIN_VERSION_base(4,12,0) |
| 12 | +#endif |
| 13 | + |
| 14 | +import Control.Monad.Trans.Class |
| 15 | + |
| 16 | +import Control.Selective |
| 17 | + |
| 18 | +-- | A newtype around @transformers@' 'Transformers.ValidationT'. |
| 19 | +newtype ValidationT e m a = ValidationT |
| 20 | + { runValidationT :: m (Validation e a) } |
| 21 | + deriving |
| 22 | + ( Functor, Foldable, Traversable |
| 23 | + ) |
| 24 | + |
| 25 | + |
| 26 | +-- TODO |
| 27 | +#if MIN_VERSION_base(4,12,0) |
| 28 | + --, Contravariant |
| 29 | +#endif |
| 30 | + |
| 31 | +-- Eq1, Ord1, Read1, Show1, |
| 32 | +--, Eq, Ord, Read, Show |
| 33 | + |
| 34 | +#if MIN_VERSION_base(4,9,0) |
| 35 | +-- , MonadFail |
| 36 | +#endif |
| 37 | +-- MonadZip, MonadIO, MonadPlus, -- alternative versions? |
| 38 | +-- Monad, MonadTrans, MonadFix, |
| 39 | + |
| 40 | +instance MonadTrans (ValidationT e) where |
| 41 | + lift = ValidationT . fmap Success |
| 42 | + |
| 43 | +deriving via Compose f (Validation e) instance (Applicative f, Semigroup e) => Applicative (ValidationT e f) |
| 44 | + |
| 45 | +-- TODO want: |
| 46 | +-- deriving via ComposeTraversable |
| 47 | +-- See https://github.com/snowleopard/selective/pull/52/ |
| 48 | +instance (Selective f, Semigroup e) => Selective (ValidationT e f) where |
| 49 | + select eab fab = ValidationT $ select (sequenceA <$> runValidationT eab) (sequenceA <$> runValidationT fab) |
| 50 | + |
| 51 | +-- TODO reproduce API of Validation |
0 commit comments