Referential Transparency, Functional Programming and Paper Writing

It may come as no surprise to hear that I'm a big fan of functional programming, and that I enjoy applying the paradigm whenever I am able. I had an interesting idea the other day concerning one of the key principles of the functional programming paradigm, referential transparency.

Referential Transparency: A function in a program is referentially transparent (has no side effects) if it can be replaced with its evaluation without changing the effect of the program.

What if referential transparency can be applied to more than just programming? Specifically, what if it could be applied to research paper writing? I think that there is some practical application to this thought process. Although the idea of research papers is not just to convey results but to also provide enough information to support one's claim. The idea of making papers referentially transparent is a convenient way to make sure that your writing is concise and to the point. In fact, many of the problems that are encountered in both paper writing and dissemination also occur in programming. Mainly, in this case, I consider the following:

  • Make it clear and to the point.
  • Provide enough context so that the statements make sense.
  • Stay in scope.

If we break up the statements that are to be conveyed and express them as functions then all of the supporting statements should be their own atomic functions as well. Referential transparency comes into place when you consider that the information being conveyed by the greater function should be able to stand on its own. That is, if we assume that the persons reading the greater statement already knows the supporting information then effect of ignoring the supporting statements should be the same as if they were read.

Note: Now if only I can apply this sort of thinking to my blog posts as well.

Carrello Demo Day! (CSCI 6050 Term Project)

Today my team for Dr. Kochut's CSCI 6050 Software Engineering class will demo our term project, Carrello. As of svn revision 412, we estimate the following metrics on the lines of code:

  • Java: 5,625
  • Freemarker Templates & HTML: 1,079
  • CSS: 665
  • XML: 1,892

Here are some screenshots, for the curious: The entire software development process (a modified version of the Waterfall model) was followed in the creation of this software system. The result is a system that I, as the Team Technical Editor, can say with confidence fulfills the functional and non-functional requirements presented to us at the beginning of the semester.

I would like to thank the entire Carrello development team: Mehdi Allahyari (Project Manager & Developer), Usman Nisar (Concept Modeler & Developer), and Haseeb Yousaf (Persistence Engineer & Developer). It has been an amazing semester! The experience we've gained and the teamwork we've demonstrated will definitely serve us well in the future.

Interesting Observation with Scala's Numeric Trait when combined with Context Bounds.

I saw something interesting this morning when I tried to create a container for a user-defined class that mixed in Scala's Numeric trait. Consider a class called MyNum (see MyNum.scala) that mixes-in Numeric. I wanted to create a container that could hold any type that mixed in the Numeric trait, including MyNum. My first intuition was to use a context bound on the type parameter. However, this seemed to only work for built-in Numeric types.

In order to fix the problem, I tried changing the context bound to a view bound. Viola, it worked!

In the following code, the commented out line will not compile. MyNumContainerB is able to hold both built-in and user-derived Numeric types.

error: ambiguous implicit values: both method stringCanBuildFrom in object Predef of type => scala.collection.generic.CanBuildFrom[String,Char,String] and method conforms in object Predef of type [A]=> <:<[A,A] match expected type val d = new MyNumContainerA(c)

I'm still trying to figure out why a context bound doesn't work. Perhaps there is a lack of implicit evidence somewhere? Anyway, some more investigation is needed. If anyone knows why this happening then please let me know!