Safe Haskell | Safe |
---|---|

Language | Haskell2010 |

Implements "patience diff" and the patience algorithm for the longest increasing subsequence problem.

# Patience diff

diff :: Ord a => [a] -> [a] -> [Item a] Source #

The difference between two lists, according to the "patience diff" algorithm.

An element of a computed difference.

Old a | Value taken from the "old" list, i.e. left argument to |

New a | Value taken from the "new" list, i.e. right argument to |

Both a a | Value taken from both lists. Both values are provided, in case your type has a non-structural definition of equality. |

## Instances

Functor Item Source # | |

Eq a => Eq (Item a) Source # | |

Data a => Data (Item a) Source # | |

Defined in Patience gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Item a -> c (Item a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Item a) # toConstr :: Item a -> Constr # dataTypeOf :: Item a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Item a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Item a)) # gmapT :: (forall b. Data b => b -> b) -> Item a -> Item a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Item a -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Item a -> r # gmapQ :: (forall d. Data d => d -> u) -> Item a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Item a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Item a -> m (Item a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Item a -> m (Item a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Item a -> m (Item a) # | |

Ord a => Ord (Item a) Source # | |

Read a => Read (Item a) Source # | |

Show a => Show (Item a) Source # | |

# Longest increasing subsequence

longestIncreasing :: [(Int, a)] -> [(Int, a)] Source #

Given: a list of distinct integers. Picks a subset of the integers in the same order, i.e. a subsequence, with the property that

- it is monotonically increasing, and
- it is at least as long as any other such subsequence.

This function uses patience sort: http://en.wikipedia.org/wiki/Patience_sorting. For implementation reasons, the actual list returned is the reverse of the subsequence.

You can pair each integer with an arbitrary annotation, which will be carried through the algorithm.