Hacker News new | comments | show | ask | jobs | submit login

I wasn't insisting on lists, but on square brackets, to match McCarthy's syntax. This golf game has strict rules!

If we drop the brackets we may as well go the whole way and use curried functions, in which case the diff function looks like:

  diff y x =
    atom y → (eq y x → ONE $ ZERO) $

    eq (car y) PLUS → 
      cons PLUS (maplist (cdr y) (\z -> diff (car z) x)) $

    eq (car y) TIMES → 
      cons PLUS (maplist (cdr y) 
                  (\z -> cons TIMES 
                           (maplist (cdr y) 
                             (\w -> z /= w → car w $ 
                                             diff (car w) x)))) $
  error ("Unexpected term" ++ show y)



Applications are open for YC Winter 2018

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: