1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module ValidationParseT where

import Control.Selective (Selective)
import Data.Error.Tree (ErrorTree)
import Data.Functor.Compose (Compose (..))
import MyPrelude

-- | A simple way to create an Applicative parser that parses from some environment.
--
-- Use with DerivingVia. Grep codebase for examples.
newtype ValidationParseT env m a = ValidationParseT {unValidationParseT :: env -> m (Validation (NonEmpty Error) a)}
  deriving
    (Functor, Applicative, Selective)
    via ( Compose
            ((->) env)
            (Compose m (Validation (NonEmpty Error)))
        )

-- | A simple way to create an Applicative parser that parses from some environment. Version that uses ErrorTree instead of Error
--
-- Use with DerivingVia. Grep codebase for examples.
newtype ValidationParseTreeT env m a = ValidationParseTreeT {unValidationParseTreeT :: env -> m (Validation (NonEmpty ErrorTree) a)}
  deriving
    (Functor, Applicative, Selective)
    via ( Compose
            ((->) env)
            (Compose m (Validation (NonEmpty ErrorTree)))
        )