Article View: comp.lang.misc
Article #5679Re: a simple miranda problem
From: Steve Vegdahl;6010;50-662;LP=A;
Date: Wed, 10 Aug 1988 23:46
Date: Wed, 10 Aug 1988 23:46
42 lines
1626 bytes
1626 bytes
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
Technical Details
Message-ID:
<2926@tekcrl.CRL.TEK.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!bellcore!rutgers!mit-eddie!uw-beaver!tektronix!tekcrl!tekchips!stevevReferences:
<FELDMARK.88Aug9114727@hanako.stars.flab.Fujitsu.JUNET> <2921@tekcrl.CRL.TEK.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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: <FELDMARK.88Aug9114727@hanako.stars.flab.Fujitsu.JUNET> <2921@tekcrl.CRL.TEK.COM> Sender: ftp@tekcrl.CRL.TEK.COM Distribution: comp Lines: 42