User loginNavigation |
LtU ForumA Variation of the Expression Problem and two Solutions in ScalaAbstract: The expression families problem can be defined as the problem of achieving reusability and composability across the components involved in a family of related datatypes and corresponding operations over those datatypes. Like with the traditional expression problem, adding new components (either variants or operations) should be possible while preserving modular and static type-safety. Moreover, different combinations of components should have different type identities and the subtyping relationships between the different combinations should be preserved. By generalizing previous work that explored the connection between type-theoretic encodings of datatypes and visitors, we propose two solutions for this problem in Scala using modular visitor components. These components can be grouped into features that can be easily composed in a feature-oriented programming style to obtain customized datatypes and operations. This is a draft paper on a topic that I think is of the interest of the readers of this forum. It motivates a variation of the expression problem and proposes two solutions in Scala inspired by type-theoretic encodings of datatypes. which program should I use? Visual Basic, C++ or DelphiI have the choice between these 3 programs to write a program which calculates the average out of 5 numbers. Principles or patterns in FPI've been reading articles on this site on and off for some time now. I thought I might ask my question here (I wasn’t sure where else to post, please bear with me). I have been programming in Java for a long time and recently I started programming in Erlang. I started developing a product (service) in Erlang. When I write code in Java, I try to adhere to principles of OOP to a great extent and I find that they actually help me. Like for instance, the Open/Closed principle makes code maintenance easy (among other things). With Open/Closed principle I write classes in such a way that there won't be a need to edit them after a few months. I think we can agree that it is risky editing a file when you re-visit after a few months. So for example, if my customer wants to calculate area of a new Shape, say, a Triangle, I can easily create a new type without modifying the existing code:
abstract class Shape {
public abstract float area();
}
class Circle extends Shape {
private float radius;
public Circle(float r) {
this.radius = r;
}
public float area() {
return 3.14 * radius * radius;
}
}
class Square extends Shape {
// override area
}
The same in Erlang would be like so, say in shapes.erl:
-module(shapes).
-export([area/1]).
area({circle, Radius}) -> 3.14 * Radius * Radius;
area({square, Side}) -> Side * Side.
To calculate the area of a Triangle, I would have to edit shapes.erl - which is risky because there is a chance I might mess up other functions. To be sure everything runs as expected, I'd have to execute unit tests on *all* functions in this module, increasing my testing time. Like I mentioned, I am creating a product which will be used as a service. Anything that will help me roll out features or fixes sooner will greatly improve my productivity and keep in mind the costs too. My question - are there any such principles or patterns in FP that I can follow? I searched online but I wasn't satisfied with the results. With time, I will eventually learn some principles but I wanted to get some tips from the experts here. I apologize if this was discussed before, I will be happy with a link to a good article. Thank you. Announcing Shapes, a functional drawing languageMerry Christmas!
Or,
This post is an announcement of the functional drawing language Shapes. (Both block quotes above are complete Shapes programs, although the first is admittedly not the easiest program to read, and the second is slightly obscured by ASCII fallbacks.) There are several reasons for the announcement:
While Shapes is a domain specific language, there exist other drawing languages for the same type of applications, so the raison d'être lies in how the end result is obtained — that is, what programming in the language is like. The primary audience for Shapes is the community of people with a taste for functional languages. Then, given that a DSL is being developed, there is an opportunity to dwell upon the general purpose aspects of the language. This is an important motivation behind the development. So, if you didn't follow the link at the top of the post, you might be wondering what Shapes is really like. Here is a short list of key properties:
Error messages are often helpful, there is a fair amount of documentation at the project web site, there is a friendly shapes-mode for Emacs, and I will personally be more than happy to help out in all ways. Please have a look at the online documentation and consider trying it out hands on! Shapes is developed under the GPL, and implemented in C++. Defining a containing function on polymorphic listI am trying to define a containing function to see if a value is one of the elements within a list which is polymorphic, but failed with the following codes: contain :: a -> [a] -> Bool> contain x [] = False > contain x (y:ys) = if x == y then True else contain x ys it seems that the problem is the 'operator' == does not support a polymorphic check? Any way can solve the problem? or any alternative solution to achieve the purpose? Thanks! Raeck Two Lightweight DSLs for Rich UI ProgrammingAbstract. User interfaces are evolving beyond bitmaps to include animation and special effects that utilize powerful graphics hardware. Unfortunately, the APIs used to implement these features are often not programmer friendly and can result in verbose code that is written in multiple languages. This paper describes our experience in improving UI library usability through lightweight domain specific languages (DSL) that are limited in scope to ease the use of library features rather than whole libraries. Lightweight DSL code is evaluated without meta-programming by using a hosting language’s conventional extensibility mechanisms such as operating overloading and automatic conversions. As a result, lightweight DSLs are easy to implement while their code can easily be modularized and manipulated by host language abstractions. We demonstrate the effectiveness of our technique through two C# lightweight DSLs for expressing databinding and pixel shading in Microsoft’s WPF UI library. Full paper available here, submitted for publication. Any problems with true union types if all values are tagged? (like in a dynamically typed system, Lisp, etc.)I was initially motivated by a desire to model "Noneable" sort of like C, and not like ML's 'a Option or Haskell's Maybe a. Wanting to distinguish a type Person from ?Person, I don't want None to be a kind of automatic bottom type of all (ref?) types. So "Noneable" looks like a union, in fact, a union of a type and a distinguished value, None. In my syntax, it would look something like this (where enum defines variants and Or is a primitive of the type language).
Wanting to not make this a special case, I was wondering if such union types present any difficulties so long as all values carry type tags in any case. So we might define Num thusly. Carrying type tag info, the values are distinguishable using pattern matching. For the "Noneable" case, we have.
Using Scala style type test syntax, we might write for Num:
My thinking is that values' type tags are already like automagical constructors, hence no need to write:
Am I missing some grand glaring whole in such a "true union" type construct given my tagged values? Any other languages have a similar type system feature that I might look at? Thanks much. Scott Practicality of Exclusively Compiler-Driven UnboxingIt is sometimes claimed in the FP community that explicit representation controls (unboxing) are unnecessary, because a good optimizer can re-arrange the data structures into unboxed forms where appropriate (I disregard hardware interaction for this discussion). Litmus questions here:
Thoughts and references? Fundamental Flaws in Current Programming Language Type SystemsI'll start with the following statement (which from different perspectives may or may not be considered valid by various parties):
In the past I have raised a number of questions in this forum regarding types and programming languages that have in the main only been answered by those who have a strongly held viewpoint. I have been spending much time over the last few years considering the viewpoints thus exhibited. The viewpoints expressed have been one of the following: Static Type are the best - various reasoning What has been unsatisfactory about the answers and the discussions that have ensued is that the subject of real world systems and the real world situations they are deployed in have not been closely examined. By this I mean that hardware related errors, system software related errors and user caused errors (including deliberate attacks) have not been brought into the discussion in relation to how the various kinds of type system can help in these conditions. Putting aside anyone's particular bent in belief as to which is the best kind of type system for programming languages, my question is: In what areas do each of the above type systems fail to provide the programmer with the tools (language constructs, abstraction facilities, etc.) to actually deal with real world troubles, problems and conditions? PLT should be about improving what we can actually do with the computing machinery that we use. With the wide range of people in this forum, what areas of research are being looked or not looked in this regard? An example problem is an application that works correctly on a single processor system but exhibits somewhat random behaviour on a dual (or more) processor system due to the seemingly random interactions/responses of a third party library or component. Please, not interested in ideological wars over this. JetBrains releases MPS (Meta Programming System)JetBrains has released their Meta Programming System (MPS). It will be a free product, with much of it under an open source license. |
Browse archives
Active forum topics |
Recent comments
8 weeks 2 days ago
8 weeks 2 days ago
8 weeks 3 days ago
8 weeks 3 days ago
9 weeks 1 hour ago
9 weeks 1 hour ago
9 weeks 1 day ago
9 weeks 1 day ago
9 weeks 1 day ago
9 weeks 1 day ago