Hacker News new | ask | show | jobs
by tempguy9999 2504 days ago
This is not relevant directly to the subject but perhaps someone in formal langs can help me. I'm interested in optimisation of (necessarily) pure functional langs. Starting with deforesting (the elimination of intermediate structures) eg.

  map(f, map(g, list(1, 2, 3)))
can be optimised trivially by a human to

  map(f.g, list(1, 2, 3))
(where f.g is functional composition) but I want to do this automatically, and the first step is to play with it. I've defined defined stuff on paper then started substituting but it's slow and, being me, error prone, when done with paper and pen.

Does anyone know of a symbolic manipulation software for haskell, or similar syntax (prefer to avoid lisp syntax if poss, but ok if nothing else) which will allow me to do this easily and get a feel for it?

Thanks

3 comments

You could use uniplate and a small AST to play more with it, the paper has examples of transformations

the paper: https://ndmitchell.com/downloads/paper-uniform_boilerplate_a...

small tutorial: https://www.cs.york.ac.uk/fp/darcs/uniplate/uniplate.htm

This seems (AFAICT) a bit higher what I'm after, but very interesting nonetheless, I'll have a play, thanks.
The compiler will generally do that sort of optimization.
Lord, that's an unhelpful comment. Some compilers do not do that eg. scala, and the cost is high hence my request.
Sounds like you are in need of transducers
Could you elaborate? A bit searching throws up some very interesting stuff but AFAICS a transducer is roughly comparable to a partial function, which doesn't relate to my request for manual expression manipulation support.

If I'm missing something, please say.

I'm referring to transducers as in clojure. You can compose 2 'map' transducers, and that results in a single 'map' of the composed mapping-functions. That's to say that the two expressions you wrote would result in the same computations if you expressed them in terms of transducers.
5 mins looking at https://stackoverflow.com/questions/26317325/can-someone-exp... I think I'm getting it. Ops accumulated and composed until they actually have to be evaluated. That's very interesting indeed, thanks, and I'll spend a couple of hours on it.

However, I was using my my example exactly as an example; I was after a symbolic manips app.

The issue of the cost of naively compiled functional languages matters to me as bad performance will kill a good thing.