Maintainer | bastiaan.heeren@ou.nl |
---|---|
Stability | provisional |
Portability | portable (depends on ghc) |
Safe Haskell | Safe |
Language | Haskell98 |
A type class for expressing choice, preference, and left-biased choice.
The Menu
datatype implements the type class by keeping all the
alternatives.
Synopsis
- class Choice a where
- data Menu k a
- (|->) :: a -> s -> Menu a s
- doneMenu :: Menu k a
- eqMenuBy :: (k -> k -> Bool) -> (a -> a -> Bool) -> Menu k a -> Menu k a -> Bool
- elems :: Menu k a -> [(k, a)]
- bests :: Menu k a -> [(k, a)]
- bestsOrdered :: (k -> k -> Ordering) -> Menu k a -> [(k, a)]
- isEmpty :: Menu k a -> Bool
- hasDone :: Menu k a -> Bool
- getByIndex :: Int -> Menu k a -> Maybe (k, a)
- cut :: Menu k a -> Menu k a
- onMenu :: Choice b => (k -> a -> b) -> b -> Menu k a -> b
- onMenuWithIndex :: Choice b => (Int -> k -> a -> b) -> b -> Menu k a -> b
Choice type class
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.
One of the alternatives in a list (unbiased).
preference :: [a] -> a Source #
Instances
Choice [a] Source # | |
Choice (Process a) Source # | |
Choice (Strategy a) Source # | |
Defined in Ideas.Common.Strategy.Abstract | |
Choice b => Choice (a -> b) Source # | |
Defined in Ideas.Common.Strategy.Choice | |
Choice (Menu k a) Source # | |
Menu data type
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 # | |
eqMenuBy :: (k -> k -> Bool) -> (a -> a -> Bool) -> Menu k a -> Menu k a -> Bool Source #
Equality with a comparison function for the elements
Queries
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.