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

Daniel Gorín dgorin at dc.uba.ar
Tue Aug 12 22:26:31 UTC 2014

On 12 Aug 2014, at 20:23, Wojciech Narczyński <wojtek at power.com.pl> wrote:

> W dniu 2014-08-12 15:01, Daniel Gorín pisze:
>> On 11 Aug 2014, at 23:16, Wojtek Narczyński <wojtek at power.com.pl> wrote:
>>> If you declare Person class in Java, you automatically get a thingy that you can readily use in UI construction, because all the fields can temporarily be null, even the required ones. In Haskell you'd need two data types: the usual proper Haskell data type, and another which wraps every field in Maybe, facilitates editing, validation, etc. Perhaps it would be possible to generate one data type from the other, or generate both from a common specification.
>> At least this part you can achieve rather easily by parametrizing each field in your record by a functor. E.g.:
>> data Person f
>>   = Person {
>>     firstName :: f String
>>   ,lastName :: f String
>>   ,birthDate :: f Date
>>   ,height :: f Int
>>   }
>> Then you get:
>>  - "Person Id" is a person with every field set in stone.
>>  - "Person Maybe" is a person with missing information.
>>  - Other functors can be easily defined (and then composed) to represent things such as Mandatory/Optional, Valid/Invalid, etc.
> I saw in the presentation submitted in another post that a similar thing has been done in Vinyl. But this won't work so well, because in the "rigid" type some fields are still supposed to remain wrapped in Maybe.

That’s not necessary a problem. If you add a field:

  ,favoriteNumber :: f (Maybe Int)

Then, in Person Maybe, a value of Nothing in favoriteNumber would mean “not entered” while Just Nothing would be “none”. Maybe you have some specific problem in mind?

More information about the Haskell-Cafe mailing list