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 15:29

>>8
I defined it a little differently, and it may in fact be buggy.

(define (from-counting-pair t p)
  (define (iter a p)
    (if (= (remainder p t) 0)
        (iter (+ a 1) (quotient p t))
        a))
  (iter 0 p))


At the very least it's less efficient because it does remainder and quotient separately. I didn't know that there is a pattern matching form receive in Scheme.

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