ideas-1.7: Feedback services for intelligent tutoring systems

Maintainer bastiaan.heeren@ou.nl provisional portable (depends on ghc) None Haskell98

Ideas.Common.View

Description

This module defines views on data-types, as described in "Canonical Forms in Interactive Exercise Assistants"

Synopsis

# Documentation

class Category * a => Arrow (a :: * -> * -> *) where #

The basic arrow class.

Instances should satisfy the following laws:

• arr id = id
• arr (f >>> g) = arr f >>> arr g
• first (arr f) = arr (first f)
• first (f >>> g) = first f >>> first g
• first f >>> arr fst = arr fst >>> f
• first f >>> arr (id *** g) = arr (id *** g) >>> first f
• first (first f) >>> arr assoc = arr assoc >>> first f

where

assoc ((a,b),c) = (a,(b,c))

The other combinators have sensible default definitions, which may be overridden for efficiency.

Minimal complete definition

arr, (first | (***))

Methods

arr :: (b -> c) -> a b c #

Lift a function to an arrow.

first :: a b c -> a (b, d) (c, d) #

Send the first component of the input through the argument arrow, and copy the rest unchanged to the output.

second :: a b c -> a (d, b) (d, c) #

A mirror image of first.

The default definition may be overridden with a more efficient version if desired.

(***) :: a b c -> a b' c' -> a (b, b') (c, c') infixr 3 #

Split the input between the two argument arrows and combine their output. Note that this is in general not a functor.

The default definition may be overridden with a more efficient version if desired.

(&&&) :: a b c -> a b c' -> a b (c, c') infixr 3 #

Fanout: send the input to both argument arrows and combine their output.

The default definition may be overridden with a more efficient version if desired.

Instances

 # Methodsarr :: (b -> c) -> Isomorphism b c #first :: Isomorphism b c -> Isomorphism (b, d) (c, d) #second :: Isomorphism b c -> Isomorphism (d, b) (d, c) #(***) :: Isomorphism b c -> Isomorphism b' c' -> Isomorphism (b, b') (c, c') #(&&&) :: Isomorphism b c -> Isomorphism b c' -> Isomorphism b (c, c') # # Methodsarr :: (b -> c) -> View b c #first :: View b c -> View (b, d) (c, d) #second :: View b c -> View (d, b) (d, c) #(***) :: View b c -> View b' c' -> View (b, b') (c, c') #(&&&) :: View b c -> View b c' -> View b (c, c') # # Methodsarr :: (b -> c) -> Matcher b c #first :: Matcher b c -> Matcher (b, d) (c, d) #second :: Matcher b c -> Matcher (d, b) (d, c) #(***) :: Matcher b c -> Matcher b' c' -> Matcher (b, b') (c, c') #(&&&) :: Matcher b c -> Matcher b c' -> Matcher b (c, c') # # Methodsarr :: (b -> c) -> Trans b c #first :: Trans b c -> Trans (b, d) (c, d) #second :: Trans b c -> Trans (d, b) (d, c) #(***) :: Trans b c -> Trans b' c' -> Trans (b, b') (c, c') #(&&&) :: Trans b c -> Trans b c' -> Trans b (c, c') # Monad m => Arrow (Kleisli m) Since: 2.1 Methodsarr :: (b -> c) -> Kleisli m b c #first :: Kleisli m b c -> Kleisli m (b, d) (c, d) #second :: Kleisli m b c -> Kleisli m (d, b) (d, c) #(***) :: Kleisli m b c -> Kleisli m b' c' -> Kleisli m (b, b') (c, c') #(&&&) :: Kleisli m b c -> Kleisli m b c' -> Kleisli m b (c, c') # Arrow (Encoder a) # Methodsarr :: (b -> c) -> Encoder a b c #first :: Encoder a b c -> Encoder a (b, d) (c, d) #second :: Encoder a b c -> Encoder a (d, b) (d, c) #(***) :: Encoder a b c -> Encoder a b' c' -> Encoder a (b, b') (c, c') #(&&&) :: Encoder a b c -> Encoder a b c' -> Encoder a b (c, c') # Arrow ((->) LiftedRep LiftedRep) Since: 2.1 Methodsarr :: (b -> c) -> (LiftedRep -> LiftedRep) b c #first :: (LiftedRep -> LiftedRep) b c -> (LiftedRep -> LiftedRep) (b, d) (c, d) #second :: (LiftedRep -> LiftedRep) b c -> (LiftedRep -> LiftedRep) (d, b) (d, c) #(***) :: (LiftedRep -> LiftedRep) b c -> (LiftedRep -> LiftedRep) b' c' -> (LiftedRep -> LiftedRep) (b, b') (c, c') #(&&&) :: (LiftedRep -> LiftedRep) b c -> (LiftedRep -> LiftedRep) b c' -> (LiftedRep -> LiftedRep) b (c, c') #

class Arrow a => ArrowChoice (a :: * -> * -> *) where #

Choice, for arrows that support it. This class underlies the if and case constructs in arrow notation.

Instances should satisfy the following laws:

• left (arr f) = arr (left f)
• left (f >>> g) = left f >>> left g
• f >>> arr Left = arr Left >>> left f
• left f >>> arr (id +++ g) = arr (id +++ g) >>> left f
• left (left f) >>> arr assocsum = arr assocsum >>> left f

where

assocsum (Left (Left x)) = Left x
assocsum (Left (Right y)) = Right (Left y)
assocsum (Right z) = Right (Right z)

The other combinators have sensible default definitions, which may be overridden for efficiency.

Methods

left :: a b c -> a (Either b d) (Either c d) #

Feed marked inputs through the argument arrow, passing the rest through unchanged to the output.

right :: a b c -> a (Either d b) (Either d c) #

A mirror image of left.

The default definition may be overridden with a more efficient version if desired.

(+++) :: a b c -> a b' c' -> a (Either b b') (Either c c') infixr 2 #

Split the input between the two argument arrows, retagging and merging their outputs. Note that this is in general not a functor.

The default definition may be overridden with a more efficient version if desired.

(|||) :: a b d -> a c d -> a (Either b c) d infixr 2 #

Fanin: Split the input between the two argument arrows and merge their outputs.

The default definition may be overridden with a more efficient version if desired.

Instances

 # Methodsleft :: Isomorphism b c -> Isomorphism (Either b d) (Either c d) #right :: Isomorphism b c -> Isomorphism (Either d b) (Either d c) #(+++) :: Isomorphism b c -> Isomorphism b' c' -> Isomorphism (Either b b') (Either c c') #(|||) :: Isomorphism b d -> Isomorphism c d -> Isomorphism (Either b c) d # # Methodsleft :: View b c -> View (Either b d) (Either c d) #right :: View b c -> View (Either d b) (Either d c) #(+++) :: View b c -> View b' c' -> View (Either b b') (Either c c') #(|||) :: View b d -> View c d -> View (Either b c) d # # Methodsleft :: Matcher b c -> Matcher (Either b d) (Either c d) #right :: Matcher b c -> Matcher (Either d b) (Either d c) #(+++) :: Matcher b c -> Matcher b' c' -> Matcher (Either b b') (Either c c') #(|||) :: Matcher b d -> Matcher c d -> Matcher (Either b c) d # # Methodsleft :: Trans b c -> Trans (Either b d) (Either c d) #right :: Trans b c -> Trans (Either d b) (Either d c) #(+++) :: Trans b c -> Trans b' c' -> Trans (Either b b') (Either c c') #(|||) :: Trans b d -> Trans c d -> Trans (Either b c) d # Monad m => ArrowChoice (Kleisli m) Since: 2.1 Methodsleft :: Kleisli m b c -> Kleisli m (Either b d) (Either c d) #right :: Kleisli m b c -> Kleisli m (Either d b) (Either d c) #(+++) :: Kleisli m b c -> Kleisli m b' c' -> Kleisli m (Either b b') (Either c c') #(|||) :: Kleisli m b d -> Kleisli m c d -> Kleisli m (Either b c) d # Since: 2.1 Methodsleft :: (LiftedRep -> LiftedRep) b c -> (LiftedRep -> LiftedRep) (Either b d) (Either c d) #right :: (LiftedRep -> LiftedRep) b c -> (LiftedRep -> LiftedRep) (Either d b) (Either d c) #(+++) :: (LiftedRep -> LiftedRep) b c -> (LiftedRep -> LiftedRep) b' c' -> (LiftedRep -> LiftedRep) (Either b b') (Either c c') #(|||) :: (LiftedRep -> LiftedRep) b d -> (LiftedRep -> LiftedRep) c d -> (LiftedRep -> LiftedRep) (Either b c) d #

class Arrow a => ArrowZero (a :: * -> * -> *) where #

Minimal complete definition

zeroArrow

Methods

zeroArrow :: a b c #

Instances

 # MethodszeroArrow :: Matcher b c # # MethodszeroArrow :: Trans b c # MonadPlus m => ArrowZero (Kleisli m) Since: 2.1 MethodszeroArrow :: Kleisli m b c #

class ArrowZero a => ArrowPlus (a :: * -> * -> *) where #

A monoid on arrows.

Minimal complete definition

(<+>)

Methods

(<+>) :: a b c -> a b c -> a b c infixr 5 #

An associative operation with identity zeroArrow.

Instances

 # Methods(<+>) :: Matcher b c -> Matcher b c -> Matcher b c # # Methods(<+>) :: Trans b c -> Trans b c -> Trans b c # MonadPlus m => ArrowPlus (Kleisli m) Since: 2.1 Methods(<+>) :: Kleisli m b c -> Kleisli m b c -> Kleisli m b c #

(>>>) :: Category k cat => cat a b -> cat b c -> cat a c infixr 1 #

Left-to-right composition

(<<<) :: Category k cat => cat b c -> cat a b -> cat a c infixr 1 #

Right-to-left composition

# IsMatch type class

class IsMatcher f where Source #

Methods

match :: f a b -> a -> Maybe b Source #

matcher :: f a b -> Matcher a b Source #

Instances

 Source # Methodsmatch :: Isomorphism a b -> a -> Maybe b Source #matcher :: Isomorphism a b -> Matcher a b Source # Source # Methodsmatch :: View a b -> a -> Maybe b Source #matcher :: View a b -> Matcher a b Source # Source # Methodsmatch :: Matcher a b -> a -> Maybe b Source #matcher :: Matcher a b -> Matcher a b Source #

matchM :: (Monad m, IsMatcher f) => f a b -> a -> m b Source #

generalized monadic variant of match

belongsTo :: IsMatcher f => a -> f a b -> Bool Source #

viewEquivalent :: (IsMatcher f, Eq b) => f a b -> a -> a -> Bool Source #

viewEquivalentWith :: IsMatcher f => (b -> b -> Bool) -> f a b -> a -> a -> Bool Source #

data Matcher a b Source #

Instances

 Source # Methodsarr :: (b -> c) -> Matcher b c #first :: Matcher b c -> Matcher (b, d) (c, d) #second :: Matcher b c -> Matcher (d, b) (d, c) #(***) :: Matcher b c -> Matcher b' c' -> Matcher (b, b') (c, c') #(&&&) :: Matcher b c -> Matcher b c' -> Matcher b (c, c') # Source # MethodszeroArrow :: Matcher b c # Source # Methods(<+>) :: Matcher b c -> Matcher b c -> Matcher b c # Source # Methodsleft :: Matcher b c -> Matcher (Either b d) (Either c d) #right :: Matcher b c -> Matcher (Either d b) (Either d c) #(+++) :: Matcher b c -> Matcher b' c' -> Matcher (Either b b') (Either c c') #(|||) :: Matcher b d -> Matcher c d -> Matcher (Either b c) d # Source # Methodsmatch :: Matcher a b -> a -> Maybe b Source #matcher :: Matcher a b -> Matcher a b Source # Source # Methodsid :: cat a a #(.) :: cat b c -> cat a b -> cat a c #

makeMatcher :: (a -> Maybe b) -> Matcher a b Source #

# IsView type class

class IsMatcher f => IsView f where Source #

Minimal complete definition: toView or both match and build.

Methods

build :: f a b -> b -> a Source #

toView :: f a b -> View a b Source #

Instances

 Source # Methodsbuild :: Isomorphism a b -> b -> a Source #toView :: Isomorphism a b -> View a b Source # Source # Methodsbuild :: View a b -> b -> a Source #toView :: View a b -> View a b Source #

simplify :: IsView f => f a b -> a -> a Source #

simplifyWith :: IsView f => (b -> b) -> f a b -> a -> a Source #

simplifyWithM :: IsView f => (b -> Maybe b) -> f a b -> a -> a Source #

canonical :: IsView f => f a b -> a -> Maybe a Source #

canonicalWith :: IsView f => (b -> b) -> f a b -> a -> Maybe a Source #

canonicalWithM :: IsView f => (b -> Maybe b) -> f a b -> a -> Maybe a Source #

isCanonical :: (IsView f, Eq a) => f a b -> a -> Bool Source #

isCanonicalWith :: IsView f => (a -> a -> Bool) -> f a b -> a -> Bool Source #

# Views

data View a b Source #

Instances

 Source # Methodsarr :: (b -> c) -> View b c #first :: View b c -> View (b, d) (c, d) #second :: View b c -> View (d, b) (d, c) #(***) :: View b c -> View b' c' -> View (b, b') (c, c') #(&&&) :: View b c -> View b c' -> View b (c, c') # Source # Methodsleft :: View b c -> View (Either b d) (Either c d) #right :: View b c -> View (Either d b) (Either d c) #(+++) :: View b c -> View b' c' -> View (Either b b') (Either c c') #(|||) :: View b d -> View c d -> View (Either b c) d # Source # Methods(<->) :: (a -> b) -> (b -> a) -> View a b Source #(!->) :: (a -> b) -> View a b Source #(<-!) :: (b -> a) -> View a b Source # Source # Methodsbuild :: View a b -> b -> a Source #toView :: View a b -> View a b Source # Source # Methodsmatch :: View a b -> a -> Maybe b Source #matcher :: View a b -> Matcher a b Source # Source # Methodsid :: cat a a #(.) :: cat b c -> cat a b -> cat a c # HasId (View a b) Source # MethodsgetId :: View a b -> Id Source #changeId :: (Id -> Id) -> View a b -> View a b Source # Identify (View a b) Source # Methods(@>) :: IsId n => n -> View a b -> View a b Source #

identity :: Category f => f a a Source #

makeView :: (a -> Maybe b) -> (b -> a) -> View a b Source #

matcherView :: Matcher a b -> (b -> a) -> View a b Source #

# Isomorphisms

data Isomorphism a b Source #

Instances

 Source # Methodsarr :: (b -> c) -> Isomorphism b c #first :: Isomorphism b c -> Isomorphism (b, d) (c, d) #second :: Isomorphism b c -> Isomorphism (d, b) (d, c) #(***) :: Isomorphism b c -> Isomorphism b' c' -> Isomorphism (b, b') (c, c') #(&&&) :: Isomorphism b c -> Isomorphism b c' -> Isomorphism b (c, c') # Source # Methodsleft :: Isomorphism b c -> Isomorphism (Either b d) (Either c d) #right :: Isomorphism b c -> Isomorphism (Either d b) (Either d c) #(+++) :: Isomorphism b c -> Isomorphism b' c' -> Isomorphism (Either b b') (Either c c') #(|||) :: Isomorphism b d -> Isomorphism c d -> Isomorphism (Either b c) d # Source # Methods(<->) :: (a -> b) -> (b -> a) -> Isomorphism a b Source #(!->) :: (a -> b) -> Isomorphism a b Source #(<-!) :: (b -> a) -> Isomorphism a b Source # Source # Methodsbuild :: Isomorphism a b -> b -> a Source #toView :: Isomorphism a b -> View a b Source # Source # Methodsmatch :: Isomorphism a b -> a -> Maybe b Source #matcher :: Isomorphism a b -> Matcher a b Source # Source # Methodsid :: cat a a #(.) :: cat b c -> cat a b -> cat a c # HasId (Isomorphism a b) Source # MethodsgetId :: Isomorphism a b -> Id Source #changeId :: (Id -> Id) -> Isomorphism a b -> Isomorphism a b Source # Identify (Isomorphism a b) Source # Methods(@>) :: IsId n => n -> Isomorphism a b -> Isomorphism a b Source #

from :: Isomorphism a b -> a -> b Source #

to :: Isomorphism a b -> b -> a Source #

# Lifting with views

class LiftView f where Source #

Minimal complete definition

liftViewIn

Methods

liftView :: View a b -> f b -> f a Source #

liftViewIn :: View a (b, c) -> f b -> f a Source #

Instances

 Source # MethodsliftView :: View a b -> Constraint b -> Constraint a Source #liftViewIn :: View a (b, c) -> Constraint b -> Constraint a Source # Source # MethodsliftView :: View a b -> Recognizer b -> Recognizer a Source #liftViewIn :: View a (b, c) -> Recognizer b -> Recognizer a Source # Source # MethodsliftView :: View a b -> Rule b -> Rule a Source #liftViewIn :: View a (b, c) -> Rule b -> Rule a Source # Source # MethodsliftView :: View a b -> Dynamic b -> Dynamic a Source #liftViewIn :: View a (b, c) -> Dynamic b -> Dynamic a Source # Source # MethodsliftView :: View a b -> Leaf b -> Leaf a Source #liftViewIn :: View a (b, c) -> Leaf b -> Leaf a Source # Source # MethodsliftView :: View a b -> LabeledStrategy b -> LabeledStrategy a Source #liftViewIn :: View a (b, c) -> LabeledStrategy b -> LabeledStrategy a Source # Source # MethodsliftView :: View a b -> Strategy b -> Strategy a Source #liftViewIn :: View a (b, c) -> Strategy b -> Strategy a Source #

# Some combinators

swapView :: Isomorphism (a, b) (b, a) Source #

listView :: View a b -> View [a] [b] Source #

Specialized version of traverseView

traverseView :: Traversable f => View a b -> View (f a) (f b) Source #

(\$<) :: Traversable f => View a (f b) -> View b c -> View a (f c) Source #

# Packaging a view

data ViewPackage where Source #

Constructors

 ViewPackage :: (Show a, Show b, Eq a) => (String -> Maybe a) -> View a b -> ViewPackage

Instances

 Source # MethodschangeId :: (Id -> Id) -> ViewPackage -> ViewPackage Source #

# Properties on views

propIdempotence :: (Show a, Eq a) => Gen a -> View a b -> Property Source #

propSoundness :: Show a => (a -> a -> Bool) -> Gen a -> View a c -> Property Source #

propNormalForm :: (Show a, Eq a) => Gen a -> View a b -> Property Source #