Skip to content
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

Replace RowToList / Row.Cons type classes with purescript-heterogeneous #18

Closed
thomashoneyman opened this issue Aug 14, 2018 · 2 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed
Milestone

Comments

@thomashoneyman
Copy link
Owner

Environment

  • purescript-halogen 4.0.0
  • purescript-halogen-formless 0.2.0

Problem

There are a huge number of boilerplate RowToList classes used to produce various transformations on heterogeneous records. This involves lots of code duplication and non-obvious type class errors for end users, and it's easy to get the constraints wrong and only realize the error later (the class will compile, but not work as expected once put into use on a particular record).

For example, there are 4 variations on essentially this same class:

class InputFieldsToFormFields (xs :: RL.RowList) (row :: # Type) (to :: # Type) | xs -> to where
  inputFieldsToFormFieldsBuilder :: RLProxy xs -> Record row -> FromScratch to

instance inputFieldsToFormFieldsNil :: InputFieldsToFormFields RL.Nil row () where
  inputFieldsToFormFieldsBuilder _ _ = identity

instance inputFieldsToFormFieldsCons
  :: ( IsSymbol name
     , Row.Cons name (InputField e i o) trash row
     , InputFieldsToFormFields tail row from
     , Row1Cons name (FormField e i o) from to
     )
  => InputFieldsToFormFields (RL.Cons name (InputField e i o) tail) row to where
  inputFieldsToFormFieldsBuilder _ r =
    first <<< rest
    where
      _name = SProxy :: SProxy name
      val = transform $ Record.get _name r
      rest = inputFieldsToFormFieldsBuilder (RLProxy :: RLProxy tail) r
      first = Builder.insert _name val
      transform (InputField input) = FormField
        { input
        , touched: false
        , result: Nothing
        }

Solution

Fortunately, @natefaubion has released purescript-heterogeneous, which might provide a way to replace a few of these classes with more straightforward, less-boilerplatey implementations.

@thomashoneyman thomashoneyman added enhancement New feature or request help wanted Extra attention is needed labels Aug 14, 2018
@thomashoneyman thomashoneyman self-assigned this Aug 14, 2018
@thomashoneyman thomashoneyman modified the milestone: 0.3.0 Aug 14, 2018
@thomashoneyman thomashoneyman added this to the 0.3.0 milestone Aug 25, 2018
@thomashoneyman
Copy link
Owner Author

It would be ideal if this allowed Formless to reduce the number of constraints present on the component and various helper functions in order to speed up compilation times.

@thomashoneyman
Copy link
Owner Author

Unable to implement, in the end, due to issues with functional dependencies and using heterogeneous as component constraints. Reverted to the original RowList approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant