Evan Martin (evan) wrote in evan_tech,
Evan Martin
evan
evan_tech

all i have to talk about is schoolwork these days


Man, this is ugly. Multiplication is implemented recursively as repeated addition, then exponentiation on top of that as repeated multiplication. But it works! And type-checks! Give it two integers and it gives you n^m.

Sadly, recursive functions mean that it's no longer guaranteed to terminate.
(fn n:int.
  (rec pwr:int->int m.
    (if m > 0 then
      (rec mul:int->int y.
        (if y > 0 then
          n+(mul (y + (-1)))
        else
          0)
      ) (pwr (m + (-1)))
    else
      1
    )
  )
)
I was about to rewrite in in Python just for fun, but then I realized you can't (?) make recursive functions with Python lambdas.
Subscribe

  • blog moved

    As described elsewhere, I've quit LiveJournal. If you're interested in my continuing posts, you should look at one of these (each contains feed…

  • dremel

    They published a paper on Dremel, my favorite previously-unpublished tool from the Google toolchest. Greg Linden discusses it: "[...] it is capable…

  • treemaps

    I finally wrote up my recent adventures in treemapping, complete with nifty clickable visualizations.

  • Post a new comment

    Error

    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 5 comments