ideas-1.5: 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

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 
(Eq k, Eq a) => Eq (Menu k a) Source 
Choice (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.