IHP 1.3 is out now!

Making a simple form type-safe

dharmatech

Posted a question to the stackoverflow ihp tag:

https://stackoverflow.com/questions/69740767/making-a-simple-form-type-safe

This one builds on the simple temperature conversion app I posted in my last question. The idea here is to have the form be generated in a type-safe manner, hopefully showing off IHP a little bit more. The type-safe form generation helpers are a nice feature of IHP and make it stand out amongst peer frameworks.

Any suggestions welcome there or here.

Thanks!

dharmatech

It's working!

I've updated the question to show the updates I made to make the example function.

Notes

As mentioned there, it's a little awkward to have to add the unused id and meta fields in Temperature just to satisfy the form generation code:

data Temperature = Temperature { 
    id :: Int, 
    farenheit :: Float, 
    meta :: MetaBag 
} deriving (Show)

Ideally we'd be able to leave those out.

Marc,

Is it conceivable that someday the form generation feature would be able to work without the id and meta fields? I.e. this way the Temperature record would just be:

data Temperature = Temperature { 
    farenheit :: Float
} deriving (Show)

If so, I'll be happy to open a github issue for this.

Or do you think that the presence of those fields is mandatory for the type-safe form generation feature?

marc PRO

Glad you figured this one out :)

The id can be removed in the future.

The meta is currently used for storing the validation results. So this field is unlikely to go away.