I’m current reading Structure and Interpretation of Computer Programs as part of a study group we started during Pablo’s Fiesta. Our goal is learn Haskell by reading this book and implementing all of the exercises in Haskell instead of Lisp. So far its been really fun and it’s actually forcing me to learn both Haskell and Lisp at the same time.

I find Lisp to be a fascinating language and it actually makes a lot more sense to me than Haskell does. Going through the exercises we came across this really interesting piece of code.

```
(define (a-plus-abs-b a b)
((if (> b 0) + -) a b))
```

Ok so what’s going on here?

- if b > 0
- return +

- else
- return -

I think it is really cool that symbols like + and – are just functions, therefore you can return them from an if statement. Here is how this might look in javascript.

```
function a_plus_abs_b(a, b) {
return (b > 0 ? plus : subtract)(a, b);
// can't return +; #sadpanda
function plus(a, b) { return a + b; };
// can't return -; #sadpanda
function subtract(a, b) { return a - b; };
}
```

Arguably not as cool as the Lisp example but it helped me understand it better.

## OMG whats the point

The point is go out and learn you a Haskell (*or any functional language other than javascript *). It’s for a greater good. I had never thought of + and – as just functions and now I’m kind of pissed that other languages don’t let you exposed them as such. Or give me a choice like Haskell does.

```
add :: Integer -> Integer -> Integer
add (a, b) = a + b;
-- Haskell allows me to call the function two ways
-- prefix notation
add (1,2) -- 3
-- infix notation
1 `add` 2 -- 3
```

Herp Derp,

-Ryan

Post Footer automatically generated by Add Post Footer Plugin for wordpress.