{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE Safe #-}
module Hasklepias.Types.Feature(
Feature(..)
, MissingReason(..)
, FeatureDefinition(..)
, applyEF
, defineEF
, defineFEF
, defineFEF2
, applyFEF
, featureR
, featureL
) where
import GHC.Read ( Read )
import GHC.Show ( Show )
import GHC.Generics ( Generic, D )
import Data.Either ( Either(..) )
import Data.Eq ( Eq )
import Data.Functor ( Functor(fmap) )
import Data.Function ( ($), (.) )
import Data.Maybe ( Maybe(..) )
import Data.String ( String )
import Hasklepias.Types.Event ( Events )
import IntervalAlgebra ( Interval, Intervallic )
newtype Feature d = Feature { Feature d -> Either MissingReason d
getFeature :: Either MissingReason d }
deriving ((forall x. Feature d -> Rep (Feature d) x)
-> (forall x. Rep (Feature d) x -> Feature d)
-> Generic (Feature d)
forall x. Rep (Feature d) x -> Feature d
forall x. Feature d -> Rep (Feature d) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall d x. Rep (Feature d) x -> Feature d
forall d x. Feature d -> Rep (Feature d) x
$cto :: forall d x. Rep (Feature d) x -> Feature d
$cfrom :: forall d x. Feature d -> Rep (Feature d) x
Generic, Int -> Feature d -> ShowS
[Feature d] -> ShowS
Feature d -> String
(Int -> Feature d -> ShowS)
-> (Feature d -> String)
-> ([Feature d] -> ShowS)
-> Show (Feature d)
forall d. Show d => Int -> Feature d -> ShowS
forall d. Show d => [Feature d] -> ShowS
forall d. Show d => Feature d -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Feature d] -> ShowS
$cshowList :: forall d. Show d => [Feature d] -> ShowS
show :: Feature d -> String
$cshow :: forall d. Show d => Feature d -> String
showsPrec :: Int -> Feature d -> ShowS
$cshowsPrec :: forall d. Show d => Int -> Feature d -> ShowS
Show, Feature d -> Feature d -> Bool
(Feature d -> Feature d -> Bool)
-> (Feature d -> Feature d -> Bool) -> Eq (Feature d)
forall d. Eq d => Feature d -> Feature d -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Feature d -> Feature d -> Bool
$c/= :: forall d. Eq d => Feature d -> Feature d -> Bool
== :: Feature d -> Feature d -> Bool
$c== :: forall d. Eq d => Feature d -> Feature d -> Bool
Eq)
instance Functor Feature where
fmap :: (a -> b) -> Feature a -> Feature b
fmap a -> b
f (Feature Either MissingReason a
x) = Either MissingReason b -> Feature b
forall d. Either MissingReason d -> Feature d
Feature ((a -> b) -> Either MissingReason a -> Either MissingReason b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f Either MissingReason a
x)
featureR :: d -> Feature d
featureR :: d -> Feature d
featureR = Either MissingReason d -> Feature d
forall d. Either MissingReason d -> Feature d
Feature (Either MissingReason d -> Feature d)
-> (d -> Either MissingReason d) -> d -> Feature d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. d -> Either MissingReason d
forall a b. b -> Either a b
Right
featureL :: MissingReason -> Feature d
featureL :: MissingReason -> Feature d
featureL = Either MissingReason d -> Feature d
forall d. Either MissingReason d -> Feature d
Feature (Either MissingReason d -> Feature d)
-> (MissingReason -> Either MissingReason d)
-> MissingReason
-> Feature d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MissingReason -> Either MissingReason d
forall a b. a -> Either a b
Left
data MissingReason =
InsufficientData
| Excluded
| Other String
| Unknown
deriving (MissingReason -> MissingReason -> Bool
(MissingReason -> MissingReason -> Bool)
-> (MissingReason -> MissingReason -> Bool) -> Eq MissingReason
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MissingReason -> MissingReason -> Bool
$c/= :: MissingReason -> MissingReason -> Bool
== :: MissingReason -> MissingReason -> Bool
$c== :: MissingReason -> MissingReason -> Bool
Eq, ReadPrec [MissingReason]
ReadPrec MissingReason
Int -> ReadS MissingReason
ReadS [MissingReason]
(Int -> ReadS MissingReason)
-> ReadS [MissingReason]
-> ReadPrec MissingReason
-> ReadPrec [MissingReason]
-> Read MissingReason
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MissingReason]
$creadListPrec :: ReadPrec [MissingReason]
readPrec :: ReadPrec MissingReason
$creadPrec :: ReadPrec MissingReason
readList :: ReadS [MissingReason]
$creadList :: ReadS [MissingReason]
readsPrec :: Int -> ReadS MissingReason
$creadsPrec :: Int -> ReadS MissingReason
Read, Int -> MissingReason -> ShowS
[MissingReason] -> ShowS
MissingReason -> String
(Int -> MissingReason -> ShowS)
-> (MissingReason -> String)
-> ([MissingReason] -> ShowS)
-> Show MissingReason
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MissingReason] -> ShowS
$cshowList :: [MissingReason] -> ShowS
show :: MissingReason -> String
$cshow :: MissingReason -> String
showsPrec :: Int -> MissingReason -> ShowS
$cshowsPrec :: Int -> MissingReason -> ShowS
Show, (forall x. MissingReason -> Rep MissingReason x)
-> (forall x. Rep MissingReason x -> MissingReason)
-> Generic MissingReason
forall x. Rep MissingReason x -> MissingReason
forall x. MissingReason -> Rep MissingReason x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MissingReason x -> MissingReason
$cfrom :: forall x. MissingReason -> Rep MissingReason x
Generic)
data FeatureDefinition e a d =
EF (Events a -> Feature d)
| FEF (Feature e -> Events a -> Feature d)
defineEF :: (Intervallic Interval a) =>
MissingReason
-> (Events a -> Maybe c)
-> (c -> d)
-> FeatureDefinition e a d
defineEF :: MissingReason
-> (Events a -> Maybe c) -> (c -> d) -> FeatureDefinition e a d
defineEF MissingReason
r Events a -> Maybe c
f c -> d
g = (Events a -> Feature d) -> FeatureDefinition e a d
forall e a d. (Events a -> Feature d) -> FeatureDefinition e a d
EF (\Events a
es ->
case Events a -> Maybe c
f Events a
es of
Maybe c
Nothing -> MissingReason -> Feature d
forall d. MissingReason -> Feature d
featureL MissingReason
r
Just c
x -> d -> Feature d
forall d. d -> Feature d
featureR (c -> d
g c
x)
)
applyEF :: FeatureDefinition e a d -> Events a -> Feature d
applyEF :: FeatureDefinition e a d -> Events a -> Feature d
applyEF (EF Events a -> Feature d
f) = Events a -> Feature d
f
defineFEF :: (Intervallic Interval a) =>
MissingReason
-> (e -> Events a -> d)
-> FeatureDefinition e a d
defineFEF :: MissingReason -> (e -> Events a -> d) -> FeatureDefinition e a d
defineFEF MissingReason
r e -> Events a -> d
g = (Feature e -> Events a -> Feature d) -> FeatureDefinition e a d
forall e a d.
(Feature e -> Events a -> Feature d) -> FeatureDefinition e a d
FEF (\(Feature Either MissingReason e
feat) Events a
es ->
case Either MissingReason e
feat of
(Left MissingReason
_) -> MissingReason -> Feature d
forall d. MissingReason -> Feature d
featureL MissingReason
r
(Right e
x) -> d -> Feature d
forall d. d -> Feature d
featureR (e -> Events a -> d
g e
x Events a
es)
)
defineFEF2 :: (Intervallic Interval a) =>
MissingReason
-> (e -> Events a -> Feature d)
-> FeatureDefinition e a d
defineFEF2 :: MissingReason
-> (e -> Events a -> Feature d) -> FeatureDefinition e a d
defineFEF2 MissingReason
r e -> Events a -> Feature d
g = (Feature e -> Events a -> Feature d) -> FeatureDefinition e a d
forall e a d.
(Feature e -> Events a -> Feature d) -> FeatureDefinition e a d
FEF (\(Feature Either MissingReason e
feat) Events a
es ->
case Either MissingReason e
feat of
(Left MissingReason
_) -> MissingReason -> Feature d
forall d. MissingReason -> Feature d
featureL MissingReason
r
(Right e
x) -> e -> Events a -> Feature d
g e
x Events a
es
)
applyFEF :: FeatureDefinition e a d -> Feature e -> Events a -> Feature d
applyFEF :: FeatureDefinition e a d -> Feature e -> Events a -> Feature d
applyFEF (FEF Feature e -> Events a -> Feature d
f) = Feature e -> Events a -> Feature d
f