[Haskell-cafe] The Good, the Bad and the GUI

Wojtek Narczyński wojtek at power.com.pl
Thu Aug 14 09:28:53 UTC 2014


On 14.08.2014 09:19, Tom Ellis wrote:
> On Wed, Aug 13, 2014 at 05:21:28PM -0700, John Lato wrote:
>> On Wed, Aug 13, 2014 at 4:21 PM, Tom Ellis
>>>      data LineItem = LineItem { name :: Maybe String
>>>                               , quantity :: Maybe Quantity
>>>                               , price :: Maybe Price }
>> Rather than this definition, what about something like:
>>
>>      data LineItemF f = LineItem
>>          { name :: f String
>>          , quantity :: f Quantity
>>          , price :: f Price }
> It seems Wojtek already objected to this approach, though perhaps that
> objection could be overcome
>
>
Hmm, perhaps like this

LineItemFi = LineItemFi
    { name :: StringFi
    , quantity :: QuantityFi
    , price :: PriceFi }


data LineItemUi f = LineItemUi
     { name :: StringUi
     , quantity :: QuantityUi
     , price :: PriceUi }

I mean 1:1 correspondence between leaf UI types that can be missing, 
validate lengths, etc. and final types that go to the backend. Maybe it 
would be possible to use type classes / families to have common 
arithmietics for calculating with both kinds of types. This does require 
TH or Generics, but it's fine.


-- 
Wojtek


More information about the Haskell-Cafe mailing list