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:08

>>7
PLT Scheme would have had an aneurysm.
HIBT? My naive translation works fine in PLT, and in Ikarus if I change (require srfi/8 srfi/26) to (import (srfi :8) (srfi :26)) and (define quotient/remainder div-and-mod). Scheme's numeric tower has been excellent for a long time. R5RS says
Implementations are encouraged, but not required, to support exact integers and exact rationals of practically  unlimited size and precision, but I believe R6RS made it a hard requirement. I found out when plotting some Julia sets that PLT even supports unlimited size and precision for complex numbers which meant I had to force it do inexact arithmetic to speed things up :)
(require srfi/8 srfi/26)
(define (cons a b)
  (* (expt 2 a)
     (expt 3 b)))
(define (fromCounting t p)
  (let iter ((a 0) (p p))
    (receive (q r) (quotient/remainder p t)
             (if (zero? r)
                 (iter (add1 a) q)
                 a))))
(define car (cut fromCounting 2 <>))
(define cdr (cut fromCounting 3 <>))

(define foo (cons 1 4))
(list foo (car foo) (cdr foo))

(define bar (cons 5 foo))
(list bar (car bar) (car (cdr bar)) (cdr (cdr bar)))

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