Saturday, June 19, 2010

Reia: Everything Is An Object

I recently added support for immutable objects to Reia.  Immutable objects work in a similar manner to objects in languages like Ruby, except once created they cannot be changed.  You can set instance variables inside of the "initialize" method (the constructor), but once they've been set, they cannot be altered.  If you want to make any changes, you'll have to create a new object.

Now I've gone one step further: all of Reia's core types are now immutable objects.  This means they are defined in Reia using the same syntax as user-defined immutable objects.  And since Reia looks a lot like Ruby, that means their implementation should be easy to understand for anyone who is familiar with Ruby.  Neat, huh?

When I originally started working on Reia, I drank Erlang-creator Joe Armstrong's kool-aid about object oriented programming.  I wanted to map OOP directly on to the Erlang asynchronous messaging model, and proceeded along that path.  When you sent a message to an object, I wanted that message to be literal, not some hand-wavey concept which was implemented as little more than function calls.

However, this meant concurrency came into play whenever you wanted to encapsulate some particular piece of state into an object.  And if the state of that object never changed, not only was this needlessly complex, it was a total waste!  Furthermore, the core types behaved as if they were "objects" when really they weren't... they pretended to work in a similar manner, but they were special blessed immutable objects.  People asked me if they could implement their own immutable objects, and sadly my answer was no.

Encapsulating immutable states has always been a pain point for Erlang.  The canonical approach, Erlang records, are a goofy and oft reviled preprocessor construct with an unwieldy syntax.  Later Erlang added an "unsupported" feature called paramaterized modules, which feel like half-assed immutable objects.  There are very few fans of either of these features.

The typical OOP thinking is that objects provide a great tool for encapsulating state.  So why do Erlang programmers have to use things like records or parameterized modules instead of objects?  Let's look at Joe Armstrong's reasoning:
Consider "time". In an OO language "time" has to be an object. But in a non OO language a "time" is a instance of a data type. For example, in Erlang there are lots of different varieties of time, these can be clearly and unambiguously specified using type declarations
Okay, great!  So if we try to get the current time in Erlang, what does it give us?

Eshell V5.7.3  (abort with ^G)
1> erlang:now().

Aiee!  What the crap is that?  In order to even begin to figure it out, we have to consult the "type declaration":

now() -> {MegaSecs, Secs, MicroSecs}

Okay, this is beginning to make more sense, after consulting the documentation.  What we've received is a tuple, which splits the current time up into megaseconds, seconds, and microseconds since January 1st, 1970.  Microseconds are split off so we don't lose precision by trying to store the value as a float, which makes sense.  However, megaseconds and seconds were split up because at the time the erlang:now()function was written, Erlang did not have support for bignums.  In other words, the type declaration is tainted with legacy.

So what if we have erlang:now() output, how do we, say, convert that into a human meaningful representation of the time, instead of the number of seconds since January 1st, 1970?  Can you guess?  Probably not...

1> calendar:now_to_local_time(erlang:now()).

Of course, the calendar module!  I'm sure that's exactly where you were thinking of looking, right?  No, not really.  The response is decently comprehensible, if you know what time it is.  However, this doesn't seem like a particularly good solution to me.  I guess Joe Armstrong likes his functions and type declarations.  I don't.  So how does Reia do it?

>> Time()
=> #<Time 2010/6/19 17:36:36>

Look at that.  Time is an object!  An immutable object in this case.  Thanks to the fact that there are functions bound to the time object's identity, it automatically knows how to display itself in a human-meaningful manner.  Because the identity of this particular piece of state is coupled to functions which automatically know how to act on it, we don't have to do a lot of digging to figure out how to make it human meaningful.  It just happens automatically.

In the end, I'm a fan of objects and Joe Armstrong is a fan of traditional functional programming principles.  They're both solutions to the same problem, but my argument is Erlang doesn't have a good solution to the problem of user-defined types and coupling the identity of states to corresponding functions designed to act on them.  In the case of the latter, Joe Armstrong thinks it's a bad thing whereas I consider it a basic, essential feature of a programming language.  As for the former, Erlang has given us records and parameterized modules, neither of which are a good solution.

I recently learned (courtesy the JRuby developers) that when Matz created Ruby, he took the core functions of Perl and mapped them all onto objects.  Every single core function in Perl has a corresponding Ruby method which belongs to a particular class.  I am now doing the same thing with Erlang, mapping all of the core functions Erlang provides onto Reia objects.

If Ruby is object-oriented Perl, then Reia is object-oriented Erlang.


luismarianoguerra said...

really nice!

how do you implement objects internally?

Matt Williamson said...

Parameterized modules + record, I'm sure.

Unknown said...

"these can be clearly and unambiguously specified using type declarations"

I think his reasoning is sound only if the type system is much more expressive (ie not just tuples & sugar).

In ghci:

Prelude Data.Time.Clock> getCurrentTime
2010-06-20 21:56:36.344085 UTC

With the type taking the shape:

data UTCTime = UTCTime {
utctDay :: Day
utctDayTime :: DiffTime

Even with haskell's less than desirable records it doesn't seem so off putting. In reality if you could provide the Erlang equivalent of a Show instance for your sugared up tuples it could look identical to your example.

Erlang suffers in this area, sure, but the way you've written it makes it sound as though OOP has a better solution for data representation in all cases.

Unknown said...

Really thanks so much for all the progress you have made so far! Keep on keeping on! By the way what happened to Ryan? Is it dead?

Tony said...

Internally Reia's objects are implemented as records and dicts. Parameterized modules aren't presently used as part of the implementation.

karmen said...

Great post! Just found your blog and I will be catching up on other posts as I get time. I'll be looking into Reia as well.

shina said...

Surveillancekart | CCTV System
cctv installation services
best home security camera system
cctv camera for home
Pestveda | Pest Control
Termite control

mariablack said...

Pc Optimization
Windows Installation
Data Recovery

shabnam praveen said...

Call girls in Kolkata
Call girls in Chandigarh
Call girls in Chandigarh
Call girls in Gurgaon
Call girls in Chandigarh
Call girls in Chandigarh

shabnam praveen said...

Call girls in Lucknow
Call girls in Guwahati
Call girls in Mumbai
Call girls in Jaipur
Call girls in Jaipur
Call girls in Jaipur
Call girls in Bangalore

keanna said...

We are building a group of Amazon Web Services mentors and members for their future assistance and help with subject. Our training will be centered around aiding placements too. We have a different HR group experts who will deal with all your meeting needs. Our Amazon Web Services Training Course Fees is moderate contrasted with others. We are the main Amazon Web Services training institute who can share video surveys of every one of our understudies. We referenced the course timings and begin date also underneath.

For More Info:- AWS Training Course in Gurgaon

dadyar said...

Hey Good news ! an interestingoffering Just click on the link below to qualify

IT said...

Security testing is must. Everybody wants security at every level of his working. as explained above failures are happened but if we test time to time then it will improve. So it depend on us how much we are serious about this.
Power System Dynamic State Estimation Motivations,Definitions, Methodologies and Future Work Project For CSE
Real Time Lateral Movement Detection based on Evidence Reasoning Network for Edge Computing Environment Project For CSE
Reliable Detection of Interest Flooding Attack in Real Deployment of Named Data Networking Project For CSE
A Lightweight and Efficient Secure Hybrid RSA (SHRSA) Messaging Scheme With Four Layered Authentication Stack Project For CSE
A Remote Sensing Image Encryption Scheme Using DNA Bases Probability andTwo Dimensional Logistic Map Project For CSE

steve said...

غسيل خزانات بمكة شركة غسيل خزانات بمكة
غسيل خزانات بجدة شركة غسيل خزانات بجدة
غسيل خزانات بالدمام شركة غسيل خزانات بالدمام

Yasmin Abdullah said...

شركة تنظيف منازل بالجبيل

شركة تنظيف منازل بالدمام

شركة تنظيف منازل بالقطيف

شركة تنظيف مجالس بالجبيل

Why should you hire a cleaning company for home?
House cleaning is part of home maintenance. It is a fact of life that must be made from dishes, washing clothes, removing dirt from the ground and so on.
No one really enjoys the hostage work, but it can't go on unattended for a long time.
While everyone can agree that cleaning the house should be done, but no one really enjoys it, people are still hesitant to think about a house cleaning company.
This happens for a number of reasons; people have doubts about strangers in their homes, they don't want people to deal with their
personal belongings, they don't feel they can justify expenses and are worried about the damage they do.

geekymr said...

nordvpn mod apk is best way to secure your online privacy. pubg mobile mod apk gives you unlimited UC

geekymr said...

isaimini tamil movies download is a free website to download tamil movies.
list of top10 webiste to download tamil dubbed movies free download

angelisaka97 said...

Permainan poker pastinya banyak di kalangan remaja hingga dewasa yang sangat menggemari permainan poker, apalagi dalam 1 id game ada banyak permainan kartunya silahkan kunjungi situs kami untuk merasakan kenyamanan dalam bermain.

server idnplay

daftar akun idn poker

idn poker deposit pulsa

agen judi poker online

agen idnplay

agen idn poker play

deposit poker menggunakan telkomsel

deposit poker menggunakan xl

daftar poker indonesia

download idn poker

download idn poker apk

apk idn poker

aplikasi idn poker

aplikasi idnplay

idn poker apk versi terbaru

idn poker versi

cara download idn poker

cara install idn poker

install idn poker

cara install idnplay

cara idnplay android

cara install idnplay android

cara login aplikasi poker

agen idn poker

agen idn poker deposit pulsa

agen poker idn yang bisa deposit pakai pulsa

deposit poker idn pakai pulsa

deposit poker idn pakai pulsa telkomsel

deposit poker idn pakai pulsa xl

cara deposit idn poker pakai pulsa

deposit idnplay

tambah kredit saldo idn poker

deposit idnplay pakai pulsa

deposit poker uang asli

tambah saldo idnplay

Dark said...

Our company provides the best services to our customers in the field of cleaning services of all kinds in the Kingdom of Saudi Arabia, which helps to get rid of dirt and insects and our company provides the best offers in the field of home services so that we gain the satisfaction of our customers along with the discounts provided by the company and also besides the distinguished workers with experience in the field next to Our latest equipment and responsiveness to our customers, and we are honored to contact you at any time
شركة الصفرات لنقل الاثاث بالرياض
شركة الصفرات لتسليك المجاري بالرياض
شركة الصفرات لعزل الخزانات بالرياض
شركة الصفرات لكشف التسربات بالرياض
شركة الصفرات للتنظيف بالرياض
شركة الصفرات لمكافحة الحشرات بالرياض
شركة الصفرات لتنظيف الخزانات بالرياض
شركة الصفرات لرش المبيدات بالرياض
شركة الصفرات لتنظيف المنازل بالرياض
شركة الصفرات لتنظيف الفلل بالرياض
Our customers just have to call the numbers inside the site to receive our company as soon as possible while providing the best cleaning services with the best discounts

Dark said...

Our company provides our customers in the city of Qatif with the best cleaning services with the strongest offers that set us apart from other companies in the field of cleaning and domestic services with the presence of distinguished workers we have experienced in the fields of cleaning and the presence of the latest and best equipment that helps to provide services in a distinct and better and easier ways that help to earn Customer satisfaction and the presence of trucks to transport luggage with furniture packaging in an excellent manner that prevents injury and keeps it as it is. You just have to contact our company to reach you at your site and provide the best offers.
شركة تنظيف بالقطيف
شركة تنظيف منازل بالقطيف
شركة تنظيف كنب بالقطيف
شركة نقل اثاث بالقطيف
شركة مكافحة حشرات بالقطيف
شركة تسليك مجاري بالقطيف
شركة الصفرات لتنظيف الشقق بالرياض
شركة الصفرات لنقل العفش بالرياض
We remind our customers that we have special offers that set us apart from other companies and huge discounts of up to 30%. Just call

Dark said...

There are many cleaning companies in Abha, but the East Stars Company remains the best cleaning company in Abha and the surrounding areas. The Eastern Stars Company is distinguished by its expertise in the field of cleaning in addition to having the best equipment used in the cleaning process and also and the presence of distinguished labor that has long experience in this field and a guarantee of 4 years Months and our company is distinguished by the use of the best insecticides that contribute to the elimination of insects, which do not cause any harm to family members and are characterized by the survival of distinctive odors only you should contact the East Stars Company
شركة تنظيف بابها
شركة تنظيف منازل بابها
شركة تنظيف خزانات بابها
شركة نقل عفش بابها
شركة مكافحة حشرات بابها
شركة تسليك مجاري بابها
شركة المثالية لنقل العفش بالدمام
شركة المثالية لمكافحة الحشرات بالدمام
شركة المثالية للتنظيف بالدمام

At your service 24 hours, we promise you the best offers and provide distinguished services that satisfy your satisfaction, God willing

Dark said...

شركه الصفرات المصنفه رقم واحد علي مستوي الخدمات المنزليه من حيث التنظيف وجوده الخدمه التي تقدمها الي عملائها بجانب الخصومات الهائله التي تمنحها بنسبه كبيره الي جميع عملائنا الموجودين داخل المملكه العربيه السعوديه حيث نتمتع بوجود نخبه من العماله المتميزه ذوي الخبره في مجال التنظيف وجميع الخدمات المنزليه ووجود احدث واجود المعدات المستخدمه في جميع المجالات التي تخص مجال الخدمات بشكل عام ووجود خصومات كبيره عليكم فقط الاتصال بشركتنا
شركة مكافحة الحمام بالرياض
شركة الصفرات لمكافحة الحشرات بالرياض
شركة الصفرات للتنظيف بالرياض
شركة الصفرات لعزل الخزانات بالرياض
شركة الصفرات لتسليك المجاري بالرياض
شركة الصفرات لتنظيف الخزانات بالرياض
شركة الصفرات لكشف التسربات بالرياض
شركة الصفرات لنقل الاثاث بالرياض
ونذكر عملائنا باننا متاحين للعمل في اي وقت خلال 24 ساعه يوميا ووجود خصومات تصل الي 40% وضمان مستوي الخدمه

salma said...

نقل عفش من جدة الى دبي نقل عفش من جدة الى دبي

customized gifts for him said...

pillow radio vintage
burlap decorative pillows
burlap pillows vintage

smartdeveloper said...

Amazing Article ! I would like to thank you for the efforts you had made for writing this awesome article.
Thanks for sharing such a nice info.I hope you will share more information like this. please keep on sharing!

internship in chennai
internship in chennai for cse
internship for mba in chennai
internship in chennai for hr
internship in chennai for mba
companies for internship in chennai
internship in chennai for ece
paid internship in chennai
internship in chennai for biotechnology
internship in chennai for students

augustwalker said...

Garmin offers a variety of items for a wide range of competitors including Garmin GPS Watches, smartwatches, and wellness trackers.

Darren Demers said...

Of course, the calendar module! I'm sure that's exactly where you were thinking of looking, right? No, not really. The response is decently comprehensible, if you know what time it is. However, this doesn't seem like a particularly good solution to me. I guess Joe Armstrong likes his functions and type declarations. I don't. So how does Reia do it? designer asian clothes uk , asian attire uk , asian style dresses uk , stitched asian suits uk , punjabi kurta pajama uk , ready made lawn suits uk , pakistani bridal dresses online usa , white cotton chikankari anarkali , yellow chikankari suit , chikankari suits online , chikankari kurti with palazzo

How they do said...

Excellent Post...I must thank you for this informative news...This is my first time to go to see it here and I am really pleased to read
it all in one place. Cctv camera dealers in Mumbai move to CCTV camera installation services in Mumbai, CCTV camera price in Mumbai @

High Da Pa Backlink said...


Try not to burn through your time in getting Dwarka accompanies

Visit: Escorts in Dwarka

Top Low-Cost Call Girls in Dwarka.

Get Services: Call Girls in Dwarka

Phenomenal Lavish escorts administration in Gurgaon on your offer

Go With: Escorts in Gurgaon

Prominent young ladies in Gurgaon let you experience exotic euphoria past your experience

Website: Call Girls in Gurgaon

Hot call young ladies for wild evenings in Gurgaon

Website: Call Girls in Gurgaon

Our Escorts: Beauties Like Models

Visit:Call Girls in Haridwar

Premium and top-class Haridwar Escorts Agency!

Go With: Call Girls in Haridwar

Lillian J. Turner said...

Nice Blog. Thanks for sharing with us. Such amazing information.

MyBlogger Club

Guest Posting Site

Best Guest Blogging Site

Guest Blogger

Guest Blogging Site

Mark_Glesson said...

I’m really happy to say it was an interesting post to read. I learned new information from your article, you are doing a great job. Hey there, I’m Jessica. I’m a web developer living in Texas. I am a fan of technology, design, and animals. I’m also interested in martial arts and baking. we are providing is for users to understand the process to Download, Install and Activate Webroot Products. For more information visit our website

Aerocity Service said...

Paharganj Escorts
Dwarka Escorts
Russian Escorts Noida
Russian Escorts Delhi
Karol Bagh escorts
Delhi Escorts Service
Escorts in Delhi
Call girls in Delhi
Delhi escort
Aerocity Escorts

Escorts Service Kolkata said...


R1se Hluoluo said...

Selanjutnya ini apabila di antara kamu seluruhnya bermain poker online domino kiu– kiu melewati suatu web agen formal serta terpercaya, informasi yang miliki oleh pemain hendak terpelihara nyaman.

Di karenakan mereka ini mau sekali apabila membernya merasakan sarana yang tidak bisa di cari melewati web poker domino kiu– kiu online abal– abal.

Bermain poker online yang menggunakan duit asli tampaknya hendak lebih seru serta pula terus jadi ketagihan buat memainkannnya apabila kamu kita terus merasakan kemenangan di masing- masing game. Hendak namun tidak banyak orang yang mengenali bila game poker ini wajib dimainkan menggunkan trik istimewa supaya bandar poker online tidak secara terus menerus menghabiskan kantong para player nya.

Martin Luiz said...

Best task authors in the Pay To Write My Assignment For Me UK can tackle task composing since they have experienced childhood in the English climate. The task aides have examined from school to a more elevated level of review in the UK establishments.

Assignment Achievers said...

Is it getting hard for you to meet the constant deadline of work and assignments are piling up and you don't know how it will be able for you to complete your assignment and case study? Don't worry get help from assignment achievers providing top case study writing service with every know-how regarding what it requires when it comes to writing the most insightful case studies.
Finance Assignment Help
Statistics Assignment Help
economics assignment help
Assignment Help Experts
Java Assignment Help
Python Assignment Help
MATLAB assignment help
Programmer help
Help with programming

Dlink Extender said...

Worried about the Dlinkap.local Not Connecting issue taking away your peace of mind? Tackle issues effectively using the troubleshooting guides present on our website.

b2b spa near me said...

I began my journey in this business when I body massage near me
was only 25 years old. Now, after 10 years my spa is famous in hyderabad.If you're thinking of booking an time with us, don't hesitate to reach me on 0000000000 as our services cannot get more superior than this

lipikabri said...

Massages are not just good for your massage spa hyderabad physical health, but they also help to improve your mental well-being. Massages calm your soul and bring you to your core. A good massage will help you sleep peacefully and allow you to think clearly.

suonerie gratis said...

Vieni sul sito Web suonerie per android per trovare le migliori suonerie di canzoni oggi.

rennasweety said...

Are you in (Hyderabad) the capital and largest city in Hyderabad? Are you searching for a place to relax after the hustle and bustle of the day? Then visit IZSPA. Our massage experts are on hand to help you unwind and loosen up. You are welcome to IZSPA the home of Pleasure and Relaxation. Explore our website and body to body spa near me find the many pleasures that await you.

Bryan Hertz said...

It was my course subject, but I didn't have enough knowledge to accomplish this, so I pay someone to do my online class. This means that anything can be considered an object, regardless of size or form. This includes things like planets, stars, and even galaxies.