[erlang-questions] Exporting a record type

Lloyd R. Prentice lloyd@REDACTED
Tue Jul 14 15:34:30 CEST 2015


Howdy Loïc,

Well, I'm a pragmatist with a job to do. And, at my age I don't have many years left to pursue worthwhile projects. For this reason and others, I value greatly the insights and guidance that folks on this list have so generously provided.

Perhaps Jesper is teasing us a bit. But to the extent that I understand the code that he has proposed, I sense serious intent and interesting ideas. Similarly, your book promises to be a cornucopia of hard-won practical insights about the craft of Erlang programming.

But to my impatient mind your book and Jesper's code share the same frustrating attributes. They raise the issues without driving the point home. I'm not complaining. Your book is still a work-in-progress and Jesper is no doubt a busy man.

So the best I can do is question the things I don't understand and, if able, help others grasp that that I do. But let's face it. Clear and simple explication of complicated matters is damned difficult. You can always spot those who really know by their talents in this regard.

So my offer holds. If you, Jesper, and other Erlang wizards have the patience and will, perhaps through give-and-take discussion we can bring greater clarity to the subtleties of data representation and Erlang records. 

Each Erlang contributor stands on the shoulder of giants. Why should others have to live through the hair-pulling hours of frustration that you, Jesper, and every other Erlang programmer of note has experienced as they've sought to express their ideas and solve problems through Erlang?

All the best,

Lloyd


Sent from my iPad

> On Jul 14, 2015, at 3:20 AM, Loïc Hoguin <essen@REDACTED> wrote:
> 
> If you have a few months with nothing to do you can figure out sofs and add human-readable documentation in OTP. Then everyone can understand Jesper's post. :-)
> 
>> On 07/14/2015 03:14 AM, lloyd@REDACTED wrote:
>> Hi Jesper et. al.
>> 
>> This way cool stuff.
>> 
>> The topic is much deeper than I thought. I need to play with it over the next few days to be sure I fully understand. But it feels like it deserves a fleshed out blog post or tutorial.
>> 
>> I'd be happy to do the heavy lifting for such a post, but no doubt many more questions will flood my child-mind before I'm competent to do so. Do you folks mind if I continue in my role as Mickey-the_Dunce?
>> 
>> Many thanks to all,
>> 
>> Lloyd
>> 
>> -----Original Message-----
>> From: "Jesper Louis Andersen" <jesper.louis.andersen@REDACTED>
>> Sent: Monday, July 13, 2015 6:03am
>> To: "Lloyd R. Prentice" <lloyd@REDACTED>
>> Cc: "Gordon Guthrie" <gguthrie@REDACTED>, "erlang-questions" <erlang-questions@REDACTED>
>> Subject: Re: [erlang-questions] Exporting a record type
>> 
>> On Sun, Jul 12, 2015 at 5:06 PM, Lloyd R. Prentice <lloyd@REDACTED>
>> wrote:
>> 
>>> Also, in your repr/2 code (which is very suggestive of neat things one can
>>> do) what is the significance of the View variable? As I see it now, it's
>>> simply a tag like thumbnail_overview, but I'm not comfortable that my
>>> understanding is correct.
>> 
>> 
>> The idea, at least, is this: a "view" of some data, book, record, ..., is a
>> way to cast that data into another structure by transforming it. I.e.,
>> "view" the data in another form. In statically typed languages, some
>> languages support built-in view-types, so you can define these
>> transformations formally, but in Erlang you have to make a more dynamic
>> resolution.
>> 
>> In its simple form, the view is just an atom(), requesting the view. But in
>> a more advanced form, the view is a language which can be executed to
>> construct a view of the data:
>> 
>> ...
>> repr(Book, {relation, R}) ->
>>     repr_rel(Book, R).
>> 
>> repr_rel(#book { genre = G } = Book, genre) ->
>>     {G, Book}.
>> 
>> Now, suppose you have a list of books, Bs:
>> 
>> Rel = [repr(B, {relation, genre}) || B <- Bs],
>> R = sofs:relation(Rel),
>> F = sofs:relation_to_family(R),
>> sofs:to_external(F).
>> 
>> If for instance you have books [#book { genre = fantasy } = A, #book {
>> genre = fantasy } = B, #book { genre = scifi } = C],
>> 
>> Then the above would return
>> 
>> [{fantasy, [A, B]}, {scifi, [C]}].
>> 
>> There are numerous tricks that can be played here, depending on what
>> transformations you need.
> 
> -- 
> Loïc Hoguin
> http://ninenines.eu
> Author of The Erlanger Playbook,
> A book about software development using Erlang



More information about the erlang-questions mailing list