monus-weighted-search-0.2.0.0: Efficient search weighted by an ordered monoid with monus.
Safe HaskellNone
LanguageHaskell2010

MonusWeightedSearch.Examples.PairingFold

Description

This module explores different ways to implement the "pairing fold".

Synopsis

Documentation

>>> :{
data Tree = Leaf | Tree :*: Tree
instance Show Tree where
  show Leaf = "."
  show (xs :*: ys) = "(" ++ show xs ++ "*" ++ show ys ++ ")"
:}

pairFold1 :: (a -> a -> a) -> [a] -> Maybe a Source #

The traditional definition of the pairing fold, as given in the original paper.

>>> pairFold1 (:*:) (replicate 5 Leaf)
Just ((.*.)*((.*.)*.))

pairFold2 :: (a -> a -> a) -> [a] -> Maybe a Source #

A function that is identical to the one above, although implemented as a fold.

>>> pairFold2 (:*:) (replicate 5 Leaf)
Just ((.*.)*((.*.)*.))

data Acc3 a Source #

Constructors

Acc3 (Maybe a) (Maybe a) 

Instances

Instances details
Foldable Acc3 Source # 
Instance details

Defined in MonusWeightedSearch.Examples.PairingFold

Methods

fold :: Monoid m => Acc3 m -> m #

foldMap :: Monoid m => (a -> m) -> Acc3 a -> m #

foldMap' :: Monoid m => (a -> m) -> Acc3 a -> m #

foldr :: (a -> b -> b) -> b -> Acc3 a -> b #

foldr' :: (a -> b -> b) -> b -> Acc3 a -> b #

foldl :: (b -> a -> b) -> b -> Acc3 a -> b #

foldl' :: (b -> a -> b) -> b -> Acc3 a -> b #

foldr1 :: (a -> a -> a) -> Acc3 a -> a #

foldl1 :: (a -> a -> a) -> Acc3 a -> a #

toList :: Acc3 a -> [a] #

null :: Acc3 a -> Bool #

length :: Acc3 a -> Int #

elem :: Eq a => a -> Acc3 a -> Bool #

maximum :: Ord a => Acc3 a -> a #

minimum :: Ord a => Acc3 a -> a #

sum :: Num a => Acc3 a -> a #

product :: Num a => Acc3 a -> a #

pairFold3 :: (a -> a -> a) -> [a] -> Maybe a Source #

This is a slightly different version to the one above: it is defunctionalised, a little.

>>> pairFold3 (:*:) (replicate 5 Leaf)
Just (.*((.*.)*(.*.)))