Docsity

Prof. Necula's CS 164: Compiling Higher-Order Languages with Function Types and UI Code, S, Study notes of Computer Science

Toggle sidebar
bg1
Prof. Necula's CS 164: Compiling
Higher-Order Languages with
Function Types and UI Code,
Study notes of Computer Science
1. Functional programming languages restrict the use of side effects and mutable data
structures are on of the reasons for side effects which cause impurity. But lists have an
immutable data structure.
2. Functional programming languages can achieve recursion thought lists because they
are naturally recursive in behavior.
3.Lists are also used heavily because manipulation of lists is an easy task, functions
having lists as arguments can be evaluated easily.
4. Functional programming languages provide higher level or abstraction and it can be
achieved only by the use of lists with higher order functions. For the same imperative
languages have to create new data structure also define it under one name. - correct
answerWhy do functional languages make such heavy use of lists?
1. High order functions and first class functions values
2. Extensive polymorphism
3. List types and operators
4. Pure Function
5. Recursion
6. Garbage Collection
7. Testing and Debugging - correct answerList several distinguishing characteristics of
functional programming languages.
A function which always requires an argument and always evaluates them before
termination. And the return value of a strict function is always abnormal such as an
infinite loop or an expression like division by zero. A strict function is undefined function
if it has undefined arguments.
pf3
pf4
pf5

Partial preview of the text

Download Prof. Necula's CS 164: Compiling Higher-Order Languages with Function Types and UI Code, S and more Study notes Computer Science in PDF only on Docsity!

Prof. Necula's CS 164: Compiling

Higher-Order Languages with

Function Types and UI Code,

Study notes of Computer Science

  1. Functional programming languages restrict the use of side effects and mutable data structures are on of the reasons for side effects which cause impurity. But lists have an immutable data structure.
  2. Functional programming languages can achieve recursion thought lists because they are naturally recursive in behavior. 3.Lists are also used heavily because manipulation of lists is an easy task, functions having lists as arguments can be evaluated easily.
  3. Functional programming languages provide higher level or abstraction and it can be achieved only by the use of lists with higher order functions. For the same imperative languages have to create new data structure also define it under one name. - correct answerWhy do functional languages make such heavy use of lists?
  4. High order functions and first class functions values
  5. Extensive polymorphism
  6. List types and operators
  7. Pure Function
  8. Recursion
  9. Garbage Collection
  10. Testing and Debugging - correct answerList several distinguishing characteristics of functional programming languages. A function which always requires an argument and always evaluates them before termination. And the return value of a strict function is always abnormal such as an infinite loop or an expression like division by zero. A strict function is undefined function if it has undefined arguments.

Consider the follwoing function: f(x) = x/x f(x) = {1 if x doesn't equal 0 {undefined is x = 0 The above function is a non-strict function for all vlaues of x except zero by f(x) is strict if x = 0. - correct answerWhat does it mean for a function to be strict? Currying is a process in which functions that accept multiple arguments or a sequence of arguments are restructured. Restructuring is done is such a way that will be equivalent to a chain of functions which accept one argument and return another function. Currying plays an important role in functional programming languages because these are those languages which generally perform most of the operations on lists. Lists are their main idea structure. - correct answerWhat is currying? What purpose does it serve in practical programs? Higher-order functions are normal functions but they either accept one or more functions as arguments or returns a function as their value. 1.Filter, 2. Map, 3. Fold - correct answerWhat is higher-order function (also known as a functional form)? Give three examples. Lists in OCaml: Lists should be homogeneous, that is they should contain elements of same type. Lists in OCaml are immutable that is once created the contents can never be changed. hd and tl functions are used hd and tl functions only work on non empty lists Lists in Lisp and Scheme Lists are heterogenous that is the elements of list can be of different types. Lists are mutable car and cdr functions are used

  1. It is not an easy task to create a new data structure (like array, require continuous memory allocation) wiithout side effects, but it is easy with the help of side effects.
  2. If we want to access an element randomly from a list, then with side effects it can - correct answerSummarize the arguments for and against side-effect free programming. S-expressions are known as Symbolic expression or syntax expression and are used to represent a nest list. It was meant for Lisp. S-expressions themselves contain the data and operation to be performed on them. S-expression is represented as a parenthesized string of symbols. In functional programming like Lis, S-expressions represent the source code as lists. Ex (p q r) - correct answerWhat is an S-expression? The different execution order of program codes is defined as evaluation strategy. The stress is given to the functions (expressions contained within the function) and their arguments. Different evaluation strategies have difference in their order of evaluation of arguments and their substitution. It is in terms of their evaluation and their substitution that take place. Applicative-order evaluation: The evaluation of the arguments is done first and then it is introduced to the function. Or we can say that before the function call, its body is simplified to the extent to which it can be. The reduction of the reducible expressions takes place. - correct answerWhat is the difference between normal-order and applicative-order evaluation? The functional programming language has first-class distinct feature. First-class value is used as a parameter for functions and returning result from functions. The value is passed as parameters to the functions of subroutines and a resultant value is returned. - correct answer4. What is a first-class value? The model is able to compute value from expression that get the arguments or parameters. It supports the passing the values to the functions and subroutines and return value from expression. It allows implementing in high level languages to substitute the values. - correct answerWhat mathematical formalism underlies functional programming? To speed up programs, one of the optimization techniques is memoization. This technique uses the concept of reusability. It means that this technique saves the result of previously calculated data, and uses them again if encountered with same expression in the program instead of redoing them. There is a tradeoff space and time. Memoization uses space to speed the execution.

Memoization is implemented in parsing (top-down parsing). Parsing means dividing the given expression into tokens so that compiler can understand. This technique is also used in operating system as page segmentation. - correct answerWhat is memoization?