User loginNavigation |
archivesSectioning a chain of operators and dot as reverse applicationI have a meager syntax proposal and am curious if anyone has explored this design, knows of a language that uses it, or can think of a problem with it. It's comprised of two aspects that work together to support certain idioms in a neighborhood of Haskell syntax. The first aspect is to generalize sectioning of binary operators to chains of binary operators where the first and/or last operand in the chain is missing. Here's a GHCi interaction: Prelude> (1 + 2*) The operator `*' [infixl 7] of a section must have lower precedence than that of the operand, namely `+' [infixl 6] in the section: `1 + 2 *'
So Haskell doesn't like the expression The second aspect is to use dot for reverse application (rather than composition). That is, x.f = f x
Dot and juxtaposition would have equal precedence allowing an OOP-like style (after modifying [1, 2, 3].map (+1).filter (>2) === filter (map [1, 2, 3] (+1)) (>2) In combination with the first aspect, we can recover composition as: f `compose` g = (.g.f) And in general we can capture the tails of OOP-like expressions like this: frob = (.map (+1).filter (>2)) Has anyone used or seen this approach or does anyone see problems with it? Policy as TypesSophia Drossopolou, Greg Meredith, and I have written a paper demonstrating that we can use Caires' behavioral-spatial types to write security policies for objects in an ocap-secure language; then it's possible for the compiler to statically check that the implementation satisfies the policy. In an object capability language, dependency injection is the only way you get access to any ability to side-effect the world; all authority is embodied in object references, which are unforgeable. To deny someone the ability to perform an action, you simply do not give them a reference to the object that performs it. We focused on demonstrating that we can type deniability in the paper. Lucius G Meredith, Mike Stay, Sophia Drossopoulou, "Policy as Types". Greg and I are currently seeking crowdfunding to build a platform called splicious; should we get funded, part of our plan is to port the spatial logic model checker to Scala and add spatial-behavioral types as annotations with a plugin. By mikestay at 2014-05-07 16:26 | LtU Forum | login or register to post comments | other blogs | 2739 reads
Currying in non-curried languagesThere are a lot of currying-in-X tutorials floating around, for example I've written my own for Javascript and PHP. Recently this one appeared on Hacker News and I got involved in the discussion, which made me think a bit harder about a peculiarity of my implementations which I've not seen in anyone else's. My blog post on PHP discusses this peculiarity in the "Returning Functions" section. My Javascript implementation linked above was written before this discovery, but I've detailed it in this followup. The idea with all implementations is that we make a 'curry' function such that the following hold:
The difference in my implementations is what happens when we're given more arguments than the function's arity:
Two consequences of this are:
My current implementations either pass all remaining arguments to the first return value (PHP) or pass one argument at a time to successive return values (Javascript; essentially "foldl ($) f args"). These work best when the returned functions are also curried, but there's no reason we can't curry them on-the-fly, or look up how many to supply and loop until we run out. We could even use such a loop to execute tail-calls while we're at it ;) This uncurrying is effectively the same as the convenience functionality shown in the first code block, but extended to our return values as well as our arguments. In other words:
I'd love to hear people's opinions on this. Is my approach better, worse or complementary to the standard approach? Has this duality been noticed before? Is this just a reason not to use n-ary functions? ;) Edit: In case you can't tell, my aim is to have expressions like "a(b, c, d, e, f, g, ...)" behave like a Haskell expression "a b c d e f g ...". By Chris Warburton at 2014-05-07 23:23 | LtU Forum | login or register to post comments | other blogs | 3479 reads
|
Browse archivesActive forum topics |
Recent comments
22 weeks 3 days ago
22 weeks 3 days ago
22 weeks 3 days ago
44 weeks 4 days ago
48 weeks 6 days ago
50 weeks 3 days ago
50 weeks 3 days ago
1 year 1 week ago
1 year 5 weeks ago
1 year 5 weeks ago