
On Tue, Aug 12, 2014 at 12:46:05PM +0200, Wojtek NarczyĆski wrote:
Continuing my VAT Invoice example, let us say a LineItem that does not have a product description (missing value), but it does have all the numeric fields filled in. It is partly erroneous, but it can be included in calculation of the total. How would you handle it with Either [Error] Invoice style code?
What sort of functionality are you looking for exactly? What's your objection to (for example) data LineItemGeneral a = LineItem { price :: Price , quantity :: Quantity , description :: a } type LineItem = LineItemGeneral String type LineItemPossiblyIncomplete = LineItemGeneral (Maybe String) type LineItemWithoutDescription = LineItemGeneral () totalValue :: LineItemGeneral a -> Value totalValue lineItem = price lineItem * quantity lineItem `totalValue` works for all sorts of line items, whether they have a description or not. Tom