{-# 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 = 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 = 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 :: forall t. HasQuery t Any => t -> Point (V t) (N t) -> Bool
inquire t
t = Any -> Bool
getAny forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 :: forall t m. HasQuery t m => t -> Point (V t) (N t) -> m
sample = forall (v :: * -> *) n m. Query v n m -> Point v n -> m
runQuery forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 :: forall m b (v :: * -> *) n.
Monoid m =>
m -> QDiagram b v n Any -> QDiagram b v n m
value m
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) = forall a. Monoid a => a
mempty
resetValue :: (Eq m, Monoid m) => QDiagram b v n m -> QDiagram b v n Any
resetValue :: forall m b (v :: * -> *) n.
(Eq m, Monoid m) =>
QDiagram b v n m -> QDiagram b v n Any
resetValue = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {a}. (Eq a, Monoid a) => a -> Any
toAny
where toAny :: a -> Any
toAny a
m | a
m forall a. Eq a => a -> a -> Bool
== 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 :: forall b (v :: * -> *) n m. QDiagram b v n m -> QDiagram b v n Any
clearValue = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b. a -> b -> a
const (Bool -> Any
Any Bool
False))