Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Going through SICP in Haskell

Name: Anonymous 2010-03-26 11:27

I've been going through SICP, first in Scheme and then in Haskell, and I started wondering...

Is my Haskell too Lisp-y?

filterAccumulate
    :: (Eq t1) =>
       (t1 -> Bool) -> (t2 -> t3 -> t3) -> t3 -> (t1 -> t2) -> t1 -> (t1 -> t1) -> t1 -> t3
filterAccumulate filter combiner nullVal term a next b =
    iter a nullVal
    where
    iter a result =
        if (a == b) then filterCombiner a result
        else iter (next a) (filterCombiner a result)
    filterCombiner a result =
        if (filter a) then combiner (term a) result
        else result

Name: Anonymous 2010-03-26 14:26

SICP's crazy fucked-up method of cons-ing counting numbers:

cons a b = (2^a)*(3^b)
car = fromCounting 2
cdr = fromCounting 3
fromCounting t p =
    iter 0 p
    where
    iter a p = if r /= 0 then a
               else iter (a+1) q
               where (q,r) = p `divMod` t


let foo = cons 1 4
foo
foo
162
car foo
1
cdr foo
4
let bar = cons 5 foo
bar
bar
6292065615217693235778429072861187721059310430214872541674093297214924518297888
car bar
5
car (cdr bar)
1
cdr (cdr bar)
4

Just blew my fuckin' mind. I'm referring, of course, to Haskell's handling of large numbers. PLT Scheme would have had an aneurysm.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List