4 ms·
In my experience it's much easier. A lot of my API relies on this. I even produce clients in other languages purely based on the API types which act as a form o
by hopia 7y ago
In my experience it's much easier. A lot of my API relies on this. I even produce clients in other languages purely based on the API types which act as a form of specification.
Haskell's compiler will generate all the logic for serialization and deserialization, leaving me to only implement the actual business logic.
- simiones 7y agoSerialization and deserialization are probably the lowest hanging fruit for this. Java has them, and it can even serialize objects with behavior. I think you're thinking of a very shallow kind of auto-generation of code, which doesn't include any kind of behavior beyond calling your API. The GP though was talking about generating the behavior based on the type specification, which is also doable in principle. For example, you could provide a complex type specification for a sorting function, and have the compiler infer the implementation. For example, you could declare a function which takes a list of `Ord a` and returns a list of `Ord a` such that the second list is a permutation of the first list and each element in the second list is <= to the next element (you of course need dependent types for this). With this type signature, the system could generate the code for a function which achieves this purpose. However, I do not believe that it will be easier to write that type signature (especially if you want to add properties like stability or time and space constraints) than it would be to write the actual sorting function yourself and sticking with `Ord a => [a] -> [a]`. I also don't think we will see anything like this in the near future that doesn't rely on a large set of pre-defined functions that the system simply fills in.
- hopia 7y agoThat was just a superficial example. If you include generics, template metaprogramming, auto derivations and such then you could achieve much more with code generation. My skills are just not advanced enough yet to fully utilize these in my programs.