1

I have a Haskell data constructor that defines an "API" (in a higher layer in my app), so I don't want to change it:

ViewModel = ViewModel { foo :: Entity Foo
                      , bar :: Entity Bar
                      , baz :: Entity Baz
                      }

and I have a function that produces lists of triples:

getViewModels :: Monad m => m [(Entity Foo, Entity Bar, Entity Baz)]

Is there a general method to uncurry ViewModel in such a way that it consumes triples? More generally, is there a way to make ViewModel consume n-tuples?

I have in mind something like this when I call my code:

do
  views <- getViewModels
  return . fmap (uncurryN ViewModel) $ views

where N is some natural number.

nomen
  • 3,626
  • 2
  • 23
  • 40
  • 1
    You can use template Haskell to generate an `uncurry` for every number (well up to the maximum number of elements a tuple can carry. – Willem Van Onsem Mar 26 '18 at 19:33
  • 2
    Though I have closed the question (and deleted my answer, for the sake of consistency -- it was the same as [the accepted one in the target](https://stackoverflow.com/a/7054444/2751851)), note that this a textbook example of an useful duplicate: essentially the same question, but phrased in a very different way. – duplode Mar 26 '18 at 20:34

0 Answers0