楼主: ReneeBK
829 4

[Lecture Notes]Functional Programming [推广有奖]

  • 1关注
  • 62粉丝

VIP

已卖:4897份资源

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49635 个
通用积分
55.6937
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57805 点
帖子
4005
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

楼主
ReneeBK 发表于 2016-4-9 09:50:45 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
CSci 555: Functional Programming
Spring Semester 2016
Lecture Notes

Sections



Schedule, Lecture Notes, and Examples

  • (26 Jan) Examine syllabus and discuss class organization.

  • Discuss programming paradigms

    • (26 Jan) A programming paradigm is "a way of conceptualizing what it means to perform computation, of structuring and organizing how tasks are to be carried out on a computer."
      -- from: Timothy A. Budd. Multiparadigm Programming in Leda, Addison-Wesley, 1995, page 3

    • (26 Jan) Programming Language Paradigms, section 1.3, pages 5-6, from the instructor's Notes on Functional Programming with Haskell

      Note: I use the phrase "programming language paradigms" in this document. More correctly, I should only say "programming paradigms" and differentiate among different styles of programming but not among languages. A language typically supports more than one style although some styles may be more directly supported than others.

      Concepts: programming language paradigm, imperative language, declarative language, functional language, relational or logic language; program state, implicit versus explicit state; sequencing versus recursion, execution of commands versus evaluation of expressions, "how" versus "what" to compute.

    • Peter Van Roy's Programming Paradigms Poster website


  • Motivate the study of functional programming

  • Introduce Scala to Java programmers

  • Explore recursion in Scala

    • (11 Feb) Recursion Concepts and Terminology: Scala Version [HTML] [PDF] [Elixir] [Lua]

      Concepts: recursion, linear and nonlinear recursion, tree recursion, backward and forward recursion, tail recursion, tail recursion optimization (also know as tail call elimination or proper tail calls), auxiliary functions, accumulating parameter (i.e. accumulator), nested functions, time and space complexity of recursive functions, termination arguments for recursive functions, preconditions and postconditions, Scala function definitions.

    • (for reference) Tail call (on Wikipedia)


  • Examine functions adapted from SICP

    • Background reading: Chapter 1 of the classic textbook SICP -- Harold Abelson and Gerald J. Sussman with Julie Sussman. Structure and Interpretation of Computer Programs, Second Edition, MIT Press, 1996:
      [book site at MIT Press] [HTML book] [SICP ebook site] [local copy of source code]

    • (9-11 Feb) First-order functions in Scala

      Concepts: Reinforces the concepts noted above for the "Notes on Scala for Java Programmers" and the notes on "Recursion Concepts and Terminology." Scala object as module, appropriate use of type inference and explicit typing of public features.
    • (11 Feb) Higher-order functions in Scala

      Definition: A higher-order function is a function that takes other functions as input and/or returns a function as its output value.

      Related definition: A first-class function is a function that is a first-class value in the language. It can be stored in a variable or some other data structure, passed to a function, or returned by a function.

      Concepts: Higher order functions allow us to capture the common aspects of a computational pattern in the fixed part of a function and pass in the variable aspects as functional arguments.

    • (for reference) Other versions

  • Study functional data structures


    • Background reading: "Functional Data Structures," Chapter 3, Paul Chiusano and Runar Bjarnason, Functional Programming in Scala

    • (16-18 Feb, 25 Feb, 1-3 Mar) Functional data structures lecture notes to accompany Chapter 3 (primarily on the List data type)
      [source]

      Concepts: referential transparency, side effect, immutable; algebraic data type, composite type, sum type (tagged, disjoint union, variant), product type (tuple, record), enumerated type, algebraic data type versus abstract data type, syntax, semantics; list, head, tail, constructor, sealed, case class, case object, distinction between case and regular objects, singleton object; polymorphism, ad hoc polymorphism, overloading, subtyping (subtype or inclusion polymorphism), parametric polymorphism (generics), type class, early versus late binding; variance, covariant, contravariant, invariant (nonvariant), variance annotation; companion object; form of the data guides the form of the algorithm, following types to implementations, pattern matching; associativity, identity element, monoid, zero element; variadic functions, apply method in companion object; data sharing, persistent data structure; when to throw exceptions, when not; backward recursion, tail recursion, accumulating parameter, auxiliary function; higher-order function, anonymous function (function literal), underscore notation in anonymous functions; fold functions, map function, filter function, flatMap function; local mutation; type inference, currying, partial application, upper and lower type bounds, view bounds; insertion sort, merge sort, total order pattern of computation, generalizing function definition; stack overflow error; method chaining, train wreck.

    • (23 Feb) No class because of instructor illness

本帖隐藏的内容

http://www.cs.olemiss.edu/~hcc/csci555/notes/555lectureNotes.html


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Programming Functional function Program Lecture

沙发
ReneeBK 发表于 2016-4-9 09:51:54
  1. /* Square Root by Newton's Method -- Version 1
  2.    Functional Programming Example
  3.    H. Conrad Cunningham, Professor, Computer and Information Science
  4.    University of Mississippi

  5.    Developed for CSci 555, Functional Programming, Spring 2016

  6. 1234567890123456789012345678901234567890123456789012345678901234567890

  7. 2016-02-10: Developed from 2015 Elixir version

  8. Function sqrt computes the square root of its argument x using
  9. Newton's method.  

  10. I adapted this square root module from an Elixir version, which was,
  11. in turn, adapted from a Lua version, which was, in turn, adapted from
  12. the Scheme code in section 1.1.7 of Abelson and Sussman's Structure
  13. and Interpretation of Computer Programs (SICP) textbook. I changed the
  14. function names to better match the Scala naming convention.

  15. I have only tested this code minimally.

  16. Scala and functional programming highlights:
  17. - Uses object to define a module
  18. - Uses type inference as much as possible (But I suggest it is
  19.   better to give return types for public functions.)
  20. - Requires return type for sqrtIter because it is recursive
  21. - Makes all functions visible.  Should hide all but sqrt.
  22. - Uses tail recursion
  23. - Calls Math.abs.

  24. */

  25. object Sqrt {

  26.   def sqrt(x: Double) = sqrtIter(1.0, x)

  27.   // Tail recursive auxiliary function
  28.   def sqrtIter(guess: Double, x: Double) : Double =
  29.     if (isGoodEnough(guess,x))
  30.       guess
  31.     else
  32.       sqrtIter(improve(guess,x),x)

  33.   def isGoodEnough(guess: Double, x: Double) =
  34.     Math.abs(square(guess)- x)< 0.001

  35.   def square(x: Double) = x * x

  36.   def improve(guess: Double, x: Double) = average(guess,x/guess)

  37.   def average(x: Double, y: Double) = (x + y) / 2

  38.   // Should implement extensive tesing externally
  39.   def main(args: Array[String]) {
  40.     println("square root of 9 is " + sqrt(9.0))
  41.   }

  42. }
复制代码

藤椅
ReneeBK 发表于 2016-4-9 09:52:45
  1. /* Square Root by Newton's Method -- Version 2
  2.    Functional Programming Example
  3.    H. Conrad Cunningham, Professor Computer and Information Science
  4.    University of Mississippi

  5.    Developed for CSci 555, Functional Programming, Spring 2016

  6. 1234567890123456789012345678901234567890123456789012345678901234567890

  7. 2016-02-10: Developed from 2015 Elixir version

  8. Function sqrt computes the square root of its argument x using
  9. Newton's method.  

  10. I adapted this square root module from an Elixir version, which was,
  11. in turn, adapted from a Lua version, which was, in turn, adapted from
  12. the Scheme code in section 1.1.7 of Abelson and Sussman's Structure
  13. and Interpretation of Computer Programs (SICP) textbook. I changed the
  14. function names to better match the Scala naming convention.

  15. I have only tested this code minimally.

  16. Scala and functional programming highlights, version 2 relative to 1:
  17. - Nests all other functions inside sqrt, hiding all but sqrt
  18. - Returns last expression's value from sqrt
  19. - Gives explicit return type for public function sqrt
  20. - Uses type inference where possible for other return values

  21. */

  22. object Sqrt {

  23.   def sqrt(x: Double): Double = {

  24.     // Tail recursive auxiliary function
  25.     def sqrtIter(guess: Double, x: Double) : Double =
  26.       if (isGoodEnough(guess,x))
  27.         guess
  28.       else
  29.         sqrtIter(improve(guess,x),x)

  30.     def isGoodEnough(guess: Double, x: Double) =
  31.       Math.abs(square(guess)- x) < 0.001

  32.     def square(x: Double) = x * x

  33.     def average(x: Double, y: Double) = (x + y) / 2

  34.     def improve(guess: Double, x: Double) = average(guess,x/guess)

  35.     sqrtIter(1.0, x)
  36.   }

  37.   // Should implement extensive tesing externally
  38.   def main(args: Array[String]) {
  39.     println("square root of 9 is " + sqrt(9.0))
  40.   }

  41. }
复制代码

板凳
condmn 发表于 2016-4-9 12:51:16

报纸
condmn 发表于 2016-4-9 12:51:17

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-29 20:28