Path: utzoo!utgpu!water!watmath!clyde!bellcore!rutgers!mit-eddie!uw-beaver!tektronix!tekcrl!tekchips!stevev From: stevev@tekchips.CRL.TEK.COM (Steve Vegdahl;6010;50-662;LP=A;) Newsgroups: comp.lang.misc Subject: Re: a simple miranda problem Keywords: functional programming Message-ID: <2926@tekcrl.CRL.TEK.COM> Date: 10 Aug 88 23:46:18 GMT References:<2921@tekcrl.CRL.TEK.COM> Sender: ftp@tekcrl.CRL.TEK.COM Distribution: comp Lines: 42 In article <2921@tekcrl.CRL.TEK.COM> willc@tekchips.CRL.TEK.COM (Will Clinger) writes: >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. Will is correct that application associates to the left, but his transformation to Scheme code does not reflect that, in that the definition of "answer" associates the applications of "twice" to the right. The definition of "answer" should be: (define answer ((((twice twice) twice) suc) 0)) yielding the value 16. Steve Vegdahl Computer Research Lab Tektronix Labs Beaverton, Oregon