So, I am trying to create a high order SML function that takes in a number and returns all the functions and returns its factors. I have done questions where I would take a list of values and return the values that are divisible but I never did anything like take a number and make a list out of it. Following the question:
Define a function
factorize = fn: int -> int listthat takes an integer and returns all its factors in a list. For example,factorize 12will return[1, 2, 3, 4, 6, 12].
The second one is a tricky one, I couldn't understand how its done so dropping it here. I would appreciate any help I get on this one.
Define a function
cfoldlthat behaves exactly same as the standardfoldlexcept that the type of the function argument does not take a 2-tuple’ instead, the input function should use the currying notation as is’a -> ’b -> ’b. Thus, the type ofcfoldlshould befn : (’a -> b -> ’b) -> ’b -> ’a list -> ’b. For example,cfoldl (fn a => fn b => a-b) 1 [1,2,3,4];will return3.
I made this for the foldl:
fun cfoldl f b [] = b
| cfoldl f b (x::xs) = cfoldl f (f (x, b)) xs;
Thank you!