Safe Haskell | None |
---|---|
Language | Haskell2010 |
Extensions |
|
- data Validator' v e
- data Validator m e o v a
- = ValidatorOuter (o m e)
- | ValidatorAction (Validator' v e)
- | ValidatorResult a
- type ValidatorArgT v r = v -> Either v v
- type ValidatorResT r v = Either v r
- effValidator :: EffClass Validator' v e => Validator' v r -> Eff e r
- runEffValidator :: forall t u m z v m1 e o w a r. Monad m => (u t r -> (r -> m (ValidatorResT z v)) -> m (ValidatorResT z v)) -> (Validator m1 e o w a -> r) -> (r -> Validator t r u v z) -> ValidatorArgT v z -> Eff r a -> m (ValidatorResT z v)
- chk :: EffClass Validator' v e => v -> Eff e v
- validator :: (v -> Bool) -> v -> Either v v
- range :: Ord v => v -> v -> v -> Either v v
- right :: Either a b -> b
- withRange :: forall r e l v. Ord v => ((v -> Either v v) -> e -> Either l r) -> v -> v -> e -> r
Overview
{-# LANGUAGE KindSignatures #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TemplateHaskell #-} import Control.THEff import Control.THEff.Validator mkEff "MyVldtr" ''Validator ''Float ''NoEff test1 :: Int -> Either Float Float -- return Left if out of range test1 i = runMyVldtr (validator (<30)) $ chk $ pi ^ i test2 :: Int -> Float -- If value is out of range, it is set on the border of the range. test2 i = withRange runMyVldtr 0 30 $ chk $ pi ^ i
>>>
test1 2
Right 9.869605
>>>
test1 3
Left 31.006279
>>>
test2 2
9.869605
>>>
test2 3
30.0
Types and functions used in mkEff
data Validator' v e Source #
Actually, the effect type - v - Type - the parameter of the effect. - e - mkEff generated type.
data Validator m e o v a Source #
Type implements link in the chain of effects.
Constructors must be named {EffectName}{Outer|WriterAction|WriterResult}
and have a specified types of fields.
- m - Or Monad (if use the Lift
) or phantom type - stub (if used NoEff
).
- o - Type of outer effect.
- a - The result of mkEff generated runEEEE... function.
ValidatorOuter (o m e) | |
ValidatorAction (Validator' v e) | |
ValidatorResult a |
type ValidatorArgT v r = v -> Either v v Source #
Type of fourth argument of runEffValidator and first argument of runEEEE.
type ValidatorResT r v = Either v r Source #
Result type of runEEEE.
effValidator :: EffClass Validator' v e => Validator' v r -> Eff e r Source #
This function is used in the mkEff
generated runEEEE functions and typically
in effect action functions. Calling the effect action.
:: forall (t :: * -> *) (u :: (* -> *) -> * -> *) (m :: * -> *) (m1 :: * -> *) (o :: (* -> *) -> * -> *). Monad m | |
=> (u t r -> (r -> m (ValidatorResT z v)) -> m (ValidatorResT z v)) | The outer effect function |
-> (Validator m1 e o w a -> r) | The chain of effects link wrapper. |
-> (r -> Validator t r u v z) | The chain of effects link unwrapper. |
-> ValidatorArgT v z | The argument of effect. A value validator function. |
-> Eff r a | |
-> m (ValidatorResT z v) |
The main function of the effect implementing.
This function is used in the mkEff
generated runEEEE functions.
Functions that use this effect
chk :: EffClass Validator' v e => v -> Eff e v Source #
Check the conditions specified by the first argument of runEEEE
Functions for substitution in the first argument runEEEEE....
validator returns Right v if the predicate returns True and Left v else.
:: Ord v | |
=> v | The lower limit of the range. |
-> v | The upper limit of the range |
-> v | The value |
-> Either v v |
If the value is outside this range, range
sets the value of the range.
Always returns Right.