Church numerals: Difference between revisions

m
→‎{{header|R}}: Syntax highlighting.
(→‎{{header|Haskell}}: Add more complex Church functions and comments...)
m (→‎{{header|R}}: Syntax highlighting.)
Line 1,840:
{{trans|Racket}}
R was inspired by Scheme and this task offers little room for creativity. As a consequence, our solution will inevitably look a lot like Racket's. Therefore, we have made this easy and just translated their solution. Alternative implementations, denoted by asterisks in their code, are separated out and denoted by "[...]Alt".
<lang rrsplus>zero<-function(f){function(x) x}
succ<-function(n){function(f){function(x) f(n(f)(x))}}
add<-function(n){function(m){function(f){function(x) m(f)(n(f)(x))}}}
Line 1,868:
[1] 64</pre>
Alternative versions (Racket's, again):
<lang rrsplus>zeroAlt<-function(x) identity
one<-function(f) f #Not actually requested by the task and only used to define Alt functions, so placed here.
oneAlt<-identity
Line 1,905:
> churchToNat(succAltAlt(four))
[1] 5</pre>
 
=={{header|Racket}}==
 
331

edits