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

Wojciech Narczyński wojtek at power.com.pl
Tue Aug 12 19:23:35 UTC 2014

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.


More information about the Haskell-Cafe mailing list