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

Daniel Gorín dgorin at dc.uba.ar
Tue Aug 12 13:01:10 UTC 2014


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.





More information about the Haskell-Cafe mailing list