Thanks for your elm-sapling example, that's an idea that I hadn't considered, I think it falls into approach (2) that I mentioned above.
> I don't think that's possible. I have noticed that Haskell has solutions for this problem e.g. https://github.com/yesodweb/persistent. In that case it's using Template Haskell which I'm not familiar with but appears to be a meta programming framework for Haskell. Elm doesn't support anything like this natively which is why I was considering approach (3) using an external tool to do code generation. Aside from Haskell there's also examples of persistence frameworks with other statically typed languages such as Java and Scala, in those cases introspection is available so solutions tend to lean on those. On Monday, 30 January 2017 12:03:07 UTC+1, Peter Damoc wrote: > > > > On Mon, Jan 30, 2017 at 12:17 PM, Oliver Searle-Barnes <[email protected] > <javascript:>> wrote: > >> # Building a Store without boilerplate >> > > I don't think that's possible. > Elm is a static language and what you seam to want is dynamic behavior. > > The practical way to solve this is to ferry type information and use that > type information to generate the dynamic behavior. > In Elm, this is done with the help of Json.Decode/Json.Encode > > This way, you can take a concrete Elm type, convert it to a generic type > like Value or String, do something dynamic based on the info you encode in > this generic type, get a generic result back and convert the result back > into some concrete Elm type. > so you can have something like: > > doSomethingDynamic : a -> (a -> Value) -> Decoder b -> b > doSomethingDynamic payload encoder decoder = > ... > > Have you seen how I have approached the issue in the exploration bellow? > https://github.com/pdamoc/elm-sapling > > > -- > There is NO FATE, we are the creators. > blog: http://damoc.ro/ > -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
