ideas-1.3.1: Feedback services for intelligent tutoring systems

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

Ideas.Common.Strategy.Choice

Contents

Description

A type class with an implementation for expressing choice and left-biased choice.

Synopsis

Choice type class

class Choice f where Source

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

Minimal complete definition

empty, single, (<|>), (>|>), (|>)

Methods

empty :: f a Source

Nothing to choose from.

single :: a -> f a Source

One element.

(<|>) :: f a -> f a -> f a infixr 3 Source

Normal (unbiased) choice.

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

Left-preference.

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

Left-biased choice.

oneof :: [a] -> f a Source

One element from a list (unbiased).

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

One of the alternatives in a list (unbiased).

Menu data type

data Menu a Source

A menu offers choices and preferences. It is an instance of the Functor and Monad type classes.

Instances

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

Equality with a comparison function for the elements

Queries

elems :: Menu a -> [a] Source

Returns all elements that are in the menu.

bests :: Menu a -> [a] Source

Returns only the best elements that are in the menu.

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

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

isEmpty :: Menu a -> Bool Source

Is the menu empty?

getByIndex :: Int -> Menu a -> Maybe a Source

Get an element from the menu by its index.

Generalized functions

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

Generalized monadic bind, with the arguments flipped.

cut :: Choice f => Menu a -> f a Source

Only keep the best elements in the menu.

cutOn :: Choice f => (a -> Bool) -> Menu a -> f a Source

mapWithIndex :: Choice f => (Int -> a -> f b) -> Menu a -> f b Source

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