[Haskell-cafe] The Good, the Bad and the GUI
Tom Ellis
tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Wed Aug 13 10:37:58 UTC 2014
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
More information about the Haskell-Cafe
mailing list