ideas-1.6: Feedback services for intelligent tutoring systems

Maintainerbastiaan.heeren@ou.nl
Stabilityprovisional
Portabilityportable (depends on ghc)
Safe HaskellSafe
LanguageHaskell98

Ideas.Common.Strategy.Choice

Contents

Description

A type class for expressing choice, preference, and left-biased choice. The Menu datatype implements the type class by keeping all the alternatives.

Synopsis

Choice type class

class Choice a where Source #

Laws: .|., ./. |> are all associative, and have empty as their unit element.

Minimal complete definition

empty, (.|.), (./.), (|>)

Methods

empty :: a Source #

Nothing to choose from.

(.|.) :: a -> a -> a infixr 3 Source #

Normal (unbiased) choice.

(./.) :: a -> a -> a infixr 3 Source #

Left-preference.

(|>) :: a -> a -> a infixr 3 Source #

Left-biased choice.

choice :: [a] -> a Source #

One of the alternatives in a list (unbiased).

preference :: [a] -> a Source #

orelse :: [a] -> a Source #

Instances

Choice [a] Source # 

Methods

empty :: [a] Source #

(.|.) :: [a] -> [a] -> [a] Source #

(./.) :: [a] -> [a] -> [a] Source #

(|>) :: [a] -> [a] -> [a] Source #

choice :: [[a]] -> [a] Source #

preference :: [[a]] -> [a] Source #

orelse :: [[a]] -> [a] Source #

Choice (Process a) Source # 
Choice (Strategy a) Source # 
Choice b => Choice (a -> b) Source # 

Methods

empty :: a -> b Source #

(.|.) :: (a -> b) -> (a -> b) -> a -> b Source #

(./.) :: (a -> b) -> (a -> b) -> a -> b Source #

(|>) :: (a -> b) -> (a -> b) -> a -> b Source #

choice :: [a -> b] -> a -> b Source #

preference :: [a -> b] -> a -> b Source #

orelse :: [a -> b] -> a -> b Source #

Choice (Menu k a) Source # 

Methods

empty :: Menu k a Source #

(.|.) :: Menu k a -> Menu k a -> Menu k a Source #

(./.) :: Menu k a -> Menu k a -> Menu k a Source #

(|>) :: Menu k a -> Menu k a -> Menu k a Source #

choice :: [Menu k a] -> Menu k a Source #

preference :: [Menu k a] -> Menu k a Source #

orelse :: [Menu k a] -> Menu k a Source #

Menu data type

data Menu k a Source #

A menu offers choices and preferences. It stores singleton bindings (thus acting as a finite map) and one special element (doneMenu). It is an instance of the Functor and Monad type classes.

Instances

Functor (Menu k) Source # 

Methods

fmap :: (a -> b) -> Menu k a -> Menu k b #

(<$) :: a -> Menu k b -> Menu k a #

(Eq k, Eq a) => Eq (Menu k a) Source # 

Methods

(==) :: Menu k a -> Menu k a -> Bool #

(/=) :: Menu k a -> Menu k a -> Bool #

Choice (Menu k a) Source # 

Methods

empty :: Menu k a Source #

(.|.) :: Menu k a -> Menu k a -> Menu k a Source #

(./.) :: Menu k a -> Menu k a -> Menu k a Source #

(|>) :: Menu k a -> Menu k a -> Menu k a Source #

choice :: [Menu k a] -> Menu k a Source #

preference :: [Menu k a] -> Menu k a Source #

orelse :: [Menu k a] -> Menu k a Source #

(|->) :: a -> s -> Menu a s infixr 5 Source #

Singleton binding

doneMenu :: Menu k a Source #

Special element for denoting success

eqMenuBy :: (k -> k -> Bool) -> (a -> a -> Bool) -> Menu k a -> Menu k a -> Bool Source #

Equality with a comparison function for the elements

Queries

elems :: Menu k a -> [(k, a)] Source #

Returns all elements that are in the menu.

bests :: Menu k a -> [(k, a)] Source #

Returns only the best elements that are in the menu with respect to left-biased choices.

bestsOrdered :: (k -> k -> Ordering) -> Menu k a -> [(k, a)] Source #

Returns only the best elements that are in the menu, with a given ordering.

isEmpty :: Menu k a -> Bool Source #

Is the menu empty?

getByIndex :: Int -> Menu k a -> Maybe (k, a) Source #

Get an element from the menu by its index.

cut :: Menu k a -> Menu k a Source #

Only keep the best elements in the menu.

Generalized functions

onMenu :: Choice b => (k -> a -> b) -> b -> Menu k a -> b Source #

Generalized monadic bind, with the arguments flipped.

onMenuWithIndex :: Choice b => (Int -> k -> a -> b) -> b -> Menu k a -> b Source #

Maps a function over a menu that also takes the index of an element.