-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ADT Forms or how to bind 2 forms? #122
Comments
AFAIK there's no way to do this with digestive-functors because the applicative interface is not powerful enough to express it. You've been thinking about it from the Haskell side, but try thinking about it from the GUI side. What would a form like this look like? You would probably have a dropdown with each of the constructors of your sum type. Then the rest of the form would have to be dynamically chosen based on the value of that dropdown. This will require some javascript to do the dynamic changing of the DOM, but digestive-functors doesn't have the ability to generate javascript. "But that's not true!" you say. "The listOf combinator uses javascript to facilitate dynamic lists." And that is true, but that uses custom coded javascript that took a lot of work to get right. Also, since lists are homogeneous, it doesn't have to handle the generic case where the structure of one part of the form is a function of a previous part of the form. You really need full-blown FRP to express this kind of thing generally. I would recommend reflex (introductory video here). |
Thanks for sharing your thoughts. I don't use form generation. I use digestive-functors-aeson in order to validate API input. Seems I have to make a monad instance for
|
@superduper wondering if you found a solution to this? |
Hi! I want to make a form for an ADT. But can't figure how do I do that.
Given we have a type:
How do we implement?
Form would look this way:
One direction I was thinking of is:
And I'm stuck here. What should we use to combine
policyForm'
andpolForm
? This could be possible if Form would be an instance of Monad, but thats not our case.There's another way: we could make a union type of Simple and Multi with each field wrapped in Maybe. Then transform it via
validate
to Simple or Multi. But it wouldn't work well if we have a bit more complexity in our ADT (likeMulti [(Text, Int)]
). Can we do better? :)Regards,
Viktor.
The text was updated successfully, but these errors were encountered: