{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Diagrams.Query
(
Query(..)
, HasQuery (..)
, sample
, inquire
, query
, value
, resetValue
, clearValue
) where
import Data.Monoid
import Diagrams.Core
class HasQuery t m | t -> m where
getQuery :: t -> Query (V t) (N t) m
instance HasQuery (Query v n m) m where
getQuery :: Query v n m -> Query (V (Query v n m)) (N (Query v n m)) m
getQuery = Query v n m -> Query (V (Query v n m)) (N (Query v n m)) m
forall a. a -> a
id
instance Monoid m => HasQuery (QDiagram b v n m) m where
getQuery :: QDiagram b v n m
-> Query (V (QDiagram b v n m)) (N (QDiagram b v n m)) m
getQuery = QDiagram b v n m
-> Query (V (QDiagram b v n m)) (N (QDiagram b v n m)) m
forall m b (v :: * -> *) n.
Monoid m =>
QDiagram b v n m -> Query v n m
query
inquire :: HasQuery t Any => t -> Point (V t) (N t) -> Bool
inquire :: t -> Point (V t) (N t) -> Bool
inquire t
t = Any -> Bool
getAny (Any -> Bool)
-> (Point (V t) (N t) -> Any) -> Point (V t) (N t) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> Point (V t) (N t) -> Any
forall t m. HasQuery t m => t -> Point (V t) (N t) -> m
sample t
t
sample :: HasQuery t m => t -> Point (V t) (N t) -> m
sample :: t -> Point (V t) (N t) -> m
sample = Query (V t) (N t) m -> Point (V t) (N t) -> m
forall (v :: * -> *) n m. Query v n m -> Point v n -> m
runQuery (Query (V t) (N t) m -> Point (V t) (N t) -> m)
-> (t -> Query (V t) (N t) m) -> t -> Point (V t) (N t) -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> Query (V t) (N t) m
forall t m. HasQuery t m => t -> Query (V t) (N t) m
getQuery
value :: Monoid m => m -> QDiagram b v n Any -> QDiagram b v n m
value :: m -> QDiagram b v n Any -> QDiagram b v n m
value m
m = (Any -> m) -> QDiagram b v n Any -> QDiagram b v n m
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Any -> m
fromAny
where fromAny :: Any -> m
fromAny (Any Bool
True) = m
m
fromAny (Any Bool
False) = m
forall a. Monoid a => a
mempty
resetValue :: (Eq m, Monoid m) => QDiagram b v n m -> QDiagram b v n Any
resetValue :: QDiagram b v n m -> QDiagram b v n Any
resetValue = (m -> Any) -> QDiagram b v n m -> QDiagram b v n Any
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap m -> Any
forall a. (Eq a, Monoid a) => a -> Any
toAny
where toAny :: a -> Any
toAny a
m | a
m a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
forall a. Monoid a => a
mempty = Bool -> Any
Any Bool
False
| Bool
otherwise = Bool -> Any
Any Bool
True
clearValue :: QDiagram b v n m -> QDiagram b v n Any
clearValue :: QDiagram b v n m -> QDiagram b v n Any
clearValue = (m -> Any) -> QDiagram b v n m -> QDiagram b v n Any
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Any -> m -> Any
forall a b. a -> b -> a
const (Bool -> Any
Any Bool
False))