I am a Haskell newbie, though had a previous Lisp/Scheme experience. Right now I am looking at the examples from SICP and trying to implement them in Haskell to get more hands-on experience. In the lecture 3b authors present a function for computing the derivatives symbolically. It contains, among others, the following lines:
(define (deriv exp var) (cond ((constant? exp var) 0) ((same-var? exp var) 1) ; ...
Further in the lecture, some more functions are defined:
(define (constant? exp var) (and (atom? exp) (not (eq? exp var))))
Is there a way to do same thing in Haskell, i.e. check for atomicity and symbolic equivalence to some other function? Or more general, what are the means of ‘disassembling’ functions in Haskell?
Your Scheme examples don’t actually examine Scheme functions. I recently did some symbolic differentiation in Haskell over values of the following type:
Instead of discriminating using
atom?oreq?you usecase(or other pattern matching) and==.