[Haskell-cafe] predicates in XML toolboxes

Henning Thielemann lemming at henning-thielemann.de
Tue Apr 12 08:32:53 EDT 2005


On Tue, 12 Apr 2005, Malcolm Wallace wrote:

> Henning Thielemann <lemming at henning-thielemann.de> writes:
>
>> The XML toolboxes HaXml, HXML and the XML toolbox uses one function type
>> (called filter) for different purposes.
>>
>> predicates                   a -> Bool
>> selectors, transformators    a -> a
>> list-valued functions        a -> [a]
>>
>> are all implemented with the one type (a -> [a]).
>>
>>   In my opinion this means a significant loss of type safety and quality of
>> documentation. Are there more type safe XML/HTML processor libraries in
>> Haskell?
>
> When we were first experimenting with designs that later became
> HaXml, we did indeed have separate notions of predicate, transformer,
> selector, and so on.  But having lots of different types like this
> meant it was more difficult to plug things together nicely into a
> combinator framework.  Thus, we decided to squash everything together
> into the filter type, so each piece was modular and could fit with
> any other piece.  I think it was a good design.

What about providing combinators for the most common cases and provide 
lifting functions for the uncommon cases, such as

liftPred :: (a -> Bool) -> (a -> [a])
liftPred p x = if p x then [x] else []

liftTrans :: (a -> b) -> (a -> [b])
liftTrans f x = [f x]

?


More information about the Haskell-Cafe mailing list