Haskell Source Reduction

I am reviewing for the upcoming Haskell exam, and I do not understand one of the questions on the last paper. Google appears nothing useful

fst(x, y) = x square i = i * i 

i) The source reduces, using a lazy Haskells score, the expression:

 fst(square(3+4), square 8) 

ii) Sources reduce using strict evaluation the same expression

iii) Indicate one advantage of lazy assessment and one advantage of strict assessment

I don’t understand what source reduction is?

+4
source share
2 answers

Abbreviation is a term from lambda calculus, which includes a transformation preserving semantics, which replaces one term with an equivalent term. For the examples you indicated, the most important type of abbreviations are

  • Replacing a name by its definition (an instance of substitution of equals for equals).
  • Beta-reduction application features.

Beta reduction is a basic rule in lambda calculus, and in a clean, lazy language like Haskell, it always preserves semantics. The beta rule is as follows:

 (\x. e) m 

can be replaced by e replacing m with x . (Substitution should avoid "capturing" free instances of x in m .)

It is possible that your instructor wants you to combine abbreviations as follows:

  • Find the function application in which the function is applied is the name.
  • Replace the name with your definition, which will be an abstraction of lambda.
  • Beta reduction of the application.
  • Do it in one step.

Note that you often have a choice about which application should be reduced; for example, in the term you give, there are two square applications and one of fst , which can be reduced in this way. (Application + can also be reduced, but const reduction requires different rules.)

Of the questions that I see, your instructor wants you to cut each term several times until you reach a normal form , and your instructor wants you to demonstrate your understanding of the different reduction strategies. The word "source" in the "original abbreviation" is redundant; abbreviation means manipulating the baseline in a language. I would formulate the questions as follows:

  • Using a reduction strategy that matches Haskell's lazy assessment, reduce the following expression to a normal normal head shape. Show each step in a sequence of abbreviations.

  • Using a reduction strategy that matches the assessment in a strict functional language, reduce the following expression to normal.

I would probably prefer to be less modest and simply name reduction strategies: on-demand reduction strategies and cost-reduction strategies.

+9
source

From the structure of the question, it probably just means “evaluate the expression manually”, for example.

 head (map primeTest (enumFromTo 1000 2000)) 

in a lazy (evaluate only if necessary) assessment,

  head (map primeTest (enumFromTo 1000 2000)) = head (map primeTest (1000 : enumFromTo 1001 2000)) = head (primeTest 1000 : map primeTest (enumFromTo 1001 2000)) = primeTest 1000 = False 

in strict (rate everything first)

  head (map primeTest (enumFromTo 1000 2000)) = head (map primeTest (1000 : enumFromTo 1001 2000)) = ... = head (map primeTest [1000, 1001, ..., 2000]) = head (primeTest 1000 : map primeTest [1001, 1002, ..., 2000]) = head (False : map primeTest [1001, 1002, ..., 2000]) = ... = head [False, False, ..., False] = False 

The only relevant place I could find is http://www.cs.bham.ac.uk/internal/modules/2009/11582.html , where "source reduction" is indicated as a "programming method". (O_O)

+7
source

Source: https://habr.com/ru/post/1310600/


All Articles