I am stuck with this SML assignment. I'm trying to make a compound function (fun premises nf). For example, it is considered to apply the function F to N, for example, the premises will be equal to 3F (F (F)). I found it to work except where zero is zero I asked the professor, but he would not tell me the answer directly. He tried to give me an indication that "what is the function times zero?" I still can not understand what stackoverflow can understand it?
Thanks .
My code:
Funny campus nf = if n & lt; 2 then if n = 0 then Fnx => F x and Fnx = & Gt; F X and FN x = & gt; F (Complex (N-1) F (x));
Example:
Val fnc = fn x = & gt; X + 1; (* Example function can be used) 5 FNC (10); (* 15 which will be corrected back *) Complex 0 FNC (10); (* Returns should be 11, 10 *)
Answer:
Funny campus n f = if n & lt; 2 then if n = 0 then Fnx => X and FN X = & gt; F X and FN X = & gt; F (complex (N-1) F (x));
I will not give you the last answer because I do not like teachers to bother;) However , I will try an etymology that I believe is easy for you to complete.
Let's start with a very simple case. Let's say "reimplement" function application, that is, let's write a function that takes a function and logic and applies the first paragraph on the second one:
fun fa fa fa = fa < / Code>
Let's use a customized function, for testing intridge integers,:
- Funny Inc. n = n + 1; Val inc = fn: int - & gt; Int-inc 1; Wall = 2: Int - Ink 1 applicable; Now it writes apply2
, which takes a function and argument and applies the ultimate function twice in the argument: this value is equal to 2: int
inc
:
funny apply2 fa = f (fa)
code> - apply2 inc 1; This value = 3: int
seems to work as you can expect, we can now apply3
, apply4
and Apply the same way. Let's see some of them in a bar:
Fun application FF = FA Fun 2 applicable FA = FA (FA) Fun 3 FA = F (F (F)) Enjoy 4 FA = F (F
It seems that we can re-write later people in the context of the former:
funny apply2 fa = F (Applied FA) Fun 3 applicable FA = F (applicable 2 FA) Fun 4 applicable FA = F (applicable 3 FA)
We can also apply
:
Fun application FA = F (applicable 0 FA ) Remember the previous definition of applicable
, they are equivalent:
Fun application FA = FA
Therefore, should be apply0
?
Fun application 0 FA = ...
No comments:
Post a Comment