User loginNavigation |
LtU ForumMonitoring whether a function happensI'm fairly new to functional programming. I found myself gravitating towards it without knowing what it was (oddly enough, I did the same with object-orientated programming about 10 years ago). I'm most interested in avoiding destructive updates, but there's something I can't get. In a test, I want to know whether a particular function has been run. I'm not sure how to go about that. In the Clean way, the function that calls that function would return a new World (I think) that somehow returns 'yes' when asked whether that function has been run. In the Haskell way, I would use monads to emulate a mutable variable (I think). I'm actually using Java, the program is event-driven (Swing). I think perhaps the World-passing metaphor is invalid because I don't control the code that calls my event handlers (and they ultimately return nothing [void]) anyway. The actual case is that when a particular label on the screen is changed, I want it to flash. I have a little animation routine that changes its background colour appropriately, but in one case, it doesn't happen. So my test should detect this. I can only see an imperative way of solving that - by adding a PropertyChangeListener that modifies an array element or equivalent to determine whether the 'background' property was changed. Is there another way - a suggested non-imperative way? I don't mind if the suggestion isn't related to Java, or if it ultimately is invalid in Java - I'm really more interested in the concepts at the moment - obviously I can do imperative stuff in Java to make this test fail (and then fix the bug so that it passes). Want to learn something newHello LtU's, I'm new here, although I've been visiting this site for more than a year. I'am a CS student, interested in programming languages and compiler construction. I'm good at C, Java, C#, doesn't matter. I love Lisp and read about it more than I did with any other language, but I never really used it much. I also love Ruby and try to use it everywhere I can. The thing is, ever since I learned Ruby, I never had the urge to learn any other programming language, and I'm starting to feel like I'm missing something. So, is it Scala? Haskell? Nemerle, OCaml? Anything else? Which one should I learn now to become a better programmer? Thanks, LuÃs Pureza P.S.: By the way... any Book recommendations? Thanks again. Continuations, yield, ES4My language of choice for everyday coding is EcmaScript, thus I am very interested in everything new in this area. I'm mostly happy with the language, the only thing I miss in it seems to continuation support. I need them to simplify my work with asynchronous processing, that seems to happen very often in my development. I want them in order to convert this async processing to look like synchronous. So for example when I need to perform a bunch of animations one after one I have to write just for(var i=0;i<animations.length;i++) performAmination(animations[i]) What I need to write now instead is some hard to understand code. Another asynchronous thing is communication with server (AJAX). var someResult = serverProxy.callSomeFunc(arg); var otherResult = serverProxy.callOtherFunc(someResult+1); Now I am writing this in CPS stile, but it is a bit tedious.
serverProxy.callSomeFunc(arg,function(someResult){
serverProxy.callOtherFunc(someResult+1, function(otherResult){
//process something here
});
})
With continuations I could hide all the async-sync conversion in proxy and all the code will just use it in synchronous way. I know that JavaScript 1.7 in Firefox 2.0 supports yield keyword and generators. Rhino already has full continuations support, and such things is possible to do in Rhino, but there is no Rhino in web-browser and in Flash player. And second question is - does somebody know whether ES4 will support continuations or just yield. Somewher I read that Brendan Eich promised continuations, but I didn't find this in ES4 draft. Cat Version 0.9I've made a major update to the Cat manual and posted a new version of the Cat interpreter and source code which is now compatible with Mono (but so far only tested on Mono 1.13.8 under Windows XP). The type checker / type inference engine is now much more mature and well-tested. The Cat interepreter and source code is all released entirely into the public domain. Any comments, suggestions, or bug reports much appreciated! By cdiggins at 2006-10-27 06:04 | LtU Forum | login or register to post comments | other blogs | 5368 reads
Growing interest in Smalltalk?I thought this was interesting - maybe there is more interest in Smalltalk now that Strongtalk has been open-sourced?
Also interesting is Ian Piumarta's work on Pepsi, although I haven't had a chance to look at all the details yet. The Type of 42The following is a reposting from my blog at http://www.artima.com/weblogs/viewpost.jsp?thread=182140. When I was designing Cat I started with the assumption that the type of a number such as 42, must be a function which pushes a primitive integer type onto the stack. So the type of 42 would be: 42 : ()->(int) The type of a function which yielded 42 would be: [42] : ()->(()->(int)) In Joy the operation for evaluating functions is "i". The equivalent in Cat is "eval". The type of eval in Cat currently is: eval : (A (A:any*)->(B:any*))->(B) This meant that the following was badly typed in Cat: 42 eval This is because eval expected a function on the top of the stack, but 42 produced a primitive on the top of the stack. You would have to instead write: [42] eval The decision for this type design was based on two things:
In assembly an operation which yields 42 and the value 42 are very different things. My thought was that I wanted to be able to trivially map Cat functions to assembly code. My concern is that the execution loop of an assembly program where values were executable would be non-trivial. I assumed you would need a switch statement and this would signficiantly hurt performance (Cat is striving to become a full competitor with real assembly code, so performance is a big concern). I am no longer convinced that this would actually be a problem. The first issue is writing the type of numbers. It appears that what is needed is the ability to name new types and express them recursively: 42 : int; int = ()->(int); The next challenge is converting to assembly code. I haven't worked out all of the details, but I believe that when generating assembly, I need to simply insert type conversion routines at key places (i.e. where an integer is being executed, or treated like a function). Do all this seem sane and rational? GADT vs. Type Classes
I'm looking for a paper or tutorial which compares/contrasts generalized algebraic data types and type classes (as found in GHC/Haskell). I get the feeling that they are some how duals of each other, and that there may be some overlap of the capabilities of each, but I don't know if I understand the essential differences which makes both desirable. For example, the standard GADT example of a tagless interpreter looks pretty similar to an equivalent built using type classes. In fact, the code for "
eval" is identical, only the type annotations differ. Any thoughts, comments?
...and here's a driver program which will work for either snippet...
Clorox - AJAX shared memoryClorox is shared memory for AJAX applications. It provides data structures that look exactly like ordinary JavaScript objects, but that make RPC calls behind the scenes to fetch data. This means that programmers don't need to think about callback functions, and Clorox also makes it very easy to define policies for caching and prefetching of data to boost performance. An open-source (Mozilla License) implementation is available at http://clorox.csail.mit.edu, and feedback is very much appreciated! Question on terminologyIs there a generic term for deriving lower-order concept form a higher-order concept? I'll illustrate this question with the following example: A language has concept of class. A class is 'defined' by notion: class myclass ...; A class is instantiated by notion myclass myvar = new myclass(); Instance of a class is an object and it appears to be a first-order concept. A particular class is a second-order concept, and 'class' as a notion of a class concept is a third-order concept. In MPS their are giving ability to "define" (?) third-order concepts with notion of fourth-order concept noted as "concept", e.g.: concept class; Thus, we may say that in each of these examples a lower-order concept is "derived" from a higher-order concept. What is the right term for this act? Constraint based hybrid typing and the Curry Howard IsomorphismI'm working on a constraint based hybrid type system. The idea is to use a constraint as the type of all the value that it could be bound to. For example a finite domain range constraint like 1..7 would be the type of integers between 1 and 7. By default this test would be done at runtime, but as there are some fairly strong ties between type inference and checking, and constraint propagation I think that it should be posible to move a lot of the checking to compile time. But the problem is that 1..7 would not ony have integers as members but also other ranges like 2..4, and most importantly, it would be a member of it self. Actually as any value could be considerd as a constraint, every term vould be a type (and a kind) and a member of itself. This would wreck havoc on the Curry Howard Isomorphism, as every proposition would be a prof of itself, and thats a rather meaningless logic language. But im not that good at type theory so I wonder exactly what do I lose by not being able to use CHI and other type theoretical works based on it? |
Browse archives
Active forum topics |
Recent comments
8 weeks 3 days ago
8 weeks 4 days ago
8 weeks 4 days ago
8 weeks 5 days ago
9 weeks 1 day ago
9 weeks 1 day ago
9 weeks 2 days ago
9 weeks 2 days ago
9 weeks 2 days ago
9 weeks 2 days ago