Path: utzoo!utgpu!water!watmath!clyde!bellcore!rutgers!mit-eddie!uw-beaver!tektronix!tekcrl!NTP server version 1.5 (26 Feb 88) ready at Wed Aug 10 1!willc
From: willc@tekcrl.TEK.COM (Will Clinger)
Newsgroups: comp.lang.misc
Subject: Re: a simple miranda problem
Summary: try associating to the left
Keywords: functional programming
Message-ID: <2921@tekcrl.CRL.TEK.COM>
Date: 10 Aug 88 18:24:48 GMT
References: 
Sender: ftp@tekcrl.CRL.TEK.COM
Reply-To: willc@tekchips.CRL.TEK.COM (Will Clinger)
Distribution: comp
Organization: Tektronix, Inc., Beaverton,  OR.
Lines: 28

I've never programmed in Miranda, but the standard practice in functional
languages is to associate to the left.  Thus I believe the Miranda program

    answer = twice twice twice suc 0
    twice f x = f (f x)
    suc x = x + 1

would be written in Scheme as

    (define twice
      (lambda (f)
        (lambda (x)
          (f (f x)))))

    (define suc
      (lambda (x)
        (+ x 1)))

    (define answer
      ((twice
        (twice
         (twice suc)))
       0))

and so the answer is 8.

William Clinger
Semantic Microsystems, Inc.