DayEight

DayEight - parameter has order 1. o Inductive Function that...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
let and High Order Functions
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
let in general let o val varName = expression o val varName2 = expression o o val varNamen = expression in o expression end;
Background image of page 2
let ’s importance Allows us to split apart parts that must be split before we use them. let example – Create a function that splits apart a list. The function should return a tuple that contains 2 lists. The first list should contain the odd elements (i.e. 1 st , 3 rd , 5 th ,…) and the second list should contain the even elements (2 nd , 4 th , 6 th , …).
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Let example Using the merge function and using the split function, create a function that implements mergeSort.
Background image of page 4
More than just convenience? Can also help a function run correctly Create a function that implements the quadratic formula o First without using let o Second using let o Third using exceptions
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
High Order Functions Function that takes a function as an argument Function that produces a function as output Every function has an order: o Base – Function that does not take parameter as a function or return a
Background image of page 6
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: parameter has order 1. o Inductive Function that takes a function as a parameter or returns a function value has order (n+1) where n is the order of its highest-order parameter or returned value. High Order Functions Consider the problem of filtering out a list based on some criteria. Create a function that accepts an integer and returns true if that number is greater than 0, false otherwise. Create a function that accepts a string and returns true if the string is a palindrome, false otherwise. Create a function that accepts a list and a function that will be used to filter out bad elements. Map Example Write a function that doubles the value of every element in a list. Write a function that squares the value of every element in a list. Write a generic map function that accepts (lst, f) and returns the following list: [ f(lst[0]), f(lst[1]), f(lst[2]), , f(lst[n]) ]...
View Full Document

This document was uploaded on 03/15/2011.

Page1 / 8

DayEight - parameter has order 1. o Inductive Function that...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online