Using language F#. Full and complete answer in order to get full credit please.
ID: 3604155 • Letter: U
Question
Using language F#. Full and complete answer in order to get full credit please. Do not copy-paste from diferent site. Thank you
1)Two powerful List functions provided by F# are List.fold and List.foldBack. These are similar to List.reduce and List.reduceBack, but more general. Both take a binary function f, an initial value i, and a list [x1;x2;x3;...;xn]. Then List.fold returns
while List.foldBack returns
In spite of this complicated behavior, they can be implemented very simply:
(Note that they don't take their arguments in the same order.)
Each of these functions can be used to implement flatten, which "flattens" a list of lists:
For example,
Compare the efficiency of flatten1 xs and flatten2 xs, both in terms of asymptotic time compexity andexperimentally. To make the analysis simpler, assume that xs is a list of the form [[1];[2];[3];...;[n]].
Explanation / Answer
using System; using System.IO; using System.Collections; using System.Linq; class program { public static void Main(string[] args) { var t = typeof(IEnumerable); var typesIEnum = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()).Where(x => t.IsAssignableFrom(x)); foreach (var types in typesIEnum) { Console.WriteLine(types.FullName); } Console.ReadLine(); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.