performance - Is there any way to make this Haskell program faster? -


mind following haskell program:

-- lambda calculus adt data term = fun (term -> term) | num !double instance show term     show (num x) = "(num "++(if fromintegral (floor x) == x show (floor x) else show x)++")"     show (fun _) = "(<function>)"  -- lambda calculus term application (#) :: term -> term -> term (fun f) # x = f x infixl 0 #   -- have floats primitives performance float_tochurch :: term float_tochurch = fun (\ (num n) -> fun (\f -> fun (\x ->      if n <= 0          x          else (f # (float_tochurch # (num (n - 1)) # f # x)))))  float_add :: term float_add = fun (\ (num x) -> fun (\ (num y) -> num (x + y)))  -- function compiled lambda calculus. -- sums nats 0 til number. sum_til :: term sum_til = (fun(\v0->((((((float_tochurch # v0) # (fun(\v1->(fun(\v2->(fun(\v3->(fun(\v4->((v3 # v2) # (((v1 # ((float_add # v2) # (num 1))) # v3) # v4))))))))))) # (fun(\v1->(fun(\v2->(fun(\v3->v3))))))) # (num 0)) # (fun(\v1->(fun(\v2->((float_add # v2) # v1)))))) # (num 0))))  -- testing main =     let n = 512*512*8     print $ (sum_til # (num n)) 

since there no fast lambda calculator around, i'm using strategy above compile terms of untyped lambda calculus haskell in order evaluate them fast. i'm impressed performance: program creates list of numbers 0 2097152 , sums them in less second on computer. faster expected - 4 times slower haskell direct equivalent - , sufficient useful goals. yet, notice i had wrap functions , terms under fun/num constructors in order satisfy type system. boxing not ideal. so, question is: possible run same lambda calculus program , same result faster? i.e., way remove boxing? (also, doesn't need use haskell.)

i don't think can keep double and avoid wrapping. think closest can just

newtype term = term (term -> term) 

but that's going make arithmetic massively slower, imagine.

the other thing can think of maybe trying cache previous results avoid recomputing them (but slower, not faster).

i am curious know on earth you've "using" though. ;-)


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -