• Complain

Chris Weed - Functional Programming with C++

Here you can read online Chris Weed - Functional Programming with C++ full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2015, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Chris Weed Functional Programming with C++
  • Book:
    Functional Programming with C++
  • Author:
  • Genre:
  • Year:
    2015
  • Rating:
    3 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 60
    • 1
    • 2
    • 3
    • 4
    • 5

Functional Programming with C++: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Functional Programming with C++" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Functional Programming with C++ covers functional programming style and features of C++. Recursive functions, lambdas, futures, and functions without side effects are a few of the C++ techniques covered in this book. This includes an extensive examination of recursive implementations of STL algorithms and functions. Functional data structures are also examined as alternatives to typical C++ implementations.

Chris Weed: author's other books


Who wrote Functional Programming with C++? Find out the surname, the name of the author of the book and a list of all author's works by series.

Functional Programming with C++ — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Functional Programming with C++" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Table of Contents
Functional Programming with C++
An Alternative Perspective onC++ By Chris Weed
Functional C++Copyright 2016 byChris Weed Allrights reserved. No part of this publication may be reproduced, distributed, ortransmitted in any form or by any means, including photocopying, recording, orother electronic or mechanical methods, without the prior written permission ofthe publisher, except in the case of brief quotations embodied in criticalreviews and certain other noncommercial uses permitted by copyright law. Forpermission requests, write to the publisher, addressed Attention: PermissionsCoordinator, at the address below. Chris Weed chrisweed@gmail.com Trademarked names may appear in this book. Rather than use atrademark symbol with every occurrence of a trademarked name, I use the namesin an editorial fashion and to the benefit of the trademark owner, with nointention of infringement of the trademark. The information in this book is distributed on an as isbasis, without warranty.

Although every precaution has been taken in thepreparation of this work, the author shall have no liability to any person orentity with respect to any loss or damage caused or alleged to be causeddirectly or indirectly by the information contained in this work.


About the Author Chris Weed is a software engineer who lives and works in the Boston area ofMassachusetts. Chris has been building C++ software since 1995, and endeavorsto use functional programming every day. He has found functional programming iskey to writing understandable and less buggy software. This has resulted ingreater productivity and happier software engineers. Additional Titles Introduction to CMake Introductionto Git-flow Introductionto Hg-flow Introduction to bjam
Introduction
Overview Functionalprogramming is experiencing a resurgence with languages like Python, Haskell,and Scala. Additional Titles Introduction to CMake Introductionto Git-flow Introductionto Hg-flow Introduction to bjam
Introduction
Overview Functionalprogramming is experiencing a resurgence with languages like Python, Haskell,and Scala.

C++ and Java have also added functional features, such as lambdasand futures. Writing C++ in a functional style using const variables, functionswithout side effects, recursive functions, and function objects results in codethat is often simpler and easier to maintain and understand, especially whenpoorly documented. This book explores functional techniques in C++ code andtheir advantages and disadvantages.

Side effects
One of the most important features of functional programmingis that programs are written almost exclusively without side effects. Accordingto Wikipedia, a function has a side effect if, in addition toreturning a value, it also modifies some state or has an observable interaction with calling functionsor the outside world. For example, a function might modify a global variable or static variable , modifyone of its arguments, raise an exception, write data to a display or file, readdata, or call other side-effecting functions.[1] Functions withoutside effects are generally referred to as pure functions, and are the normfor functional languages.

These functions only produce output variables basedon the input arguments. However, C++ code commonly includes functions withmutable arguments, references global, static, or member variables, or callsother non-pure functions. A useful property ofpure functions is that when called with the same arguments always results inthe same output. Due to this, functional languages can cache the reproducibleresult using a process called memoization for following calls to purefunctions. A non-pure function is based on some external state or changes anexternal state, which is often difficult to reproduce, test, or understand.

Sequences
STL algorithms are generallybased on iterating over a sequence of values or objects accessed between thebegin and end iterators.

The typical segmentation of a list in a functionallanguage is between the head object and tail list. STL containers provide thehead object by dereferencing the begin iterator, and the tail list isavailable between the next iterator, accessed by std::next(begin), and theend iterator. Additionally, an empty list is when the begin and enditerator are equal, such that there are no objects between them. The Algorithmchapter uses this model of a sequence, extensively.

Compiler
The Apple LLVM version 6.1.0 compiler was used to compilethe samples in this book using the -O3 option that includes tail-calloptimization. This optimization setting is necessary in release and debug modebuilds with deep recursion, since the program will exceed the stack sizewithout it and result in a segmentation fault.

The option -std=c++11 was alsoused for building all of the code samples. For code samples related to C++14,the -std=c++14 option was used instead.

Performance
Functional programming generally involves an abstractionpenalty that prevents the code from achieving the absolute optimal performance,however, that is rarely necessary for an entire program. Often, only small,performance critical sections of a program need to be optimized for goodperformance. Restricting side effects to those sections allows nearly optimalperformance while maintaining readable and error free code throughout theremaining parts.
Algorithms
Recursive functions
Recursive functions are a staple of functional languages andmany algorithms are more easily implemented than with a strictly iterativeformulation.

A difficulty with recursive algorithms is a computers stacklimit, which will be violated with too many recursive calls. Modern C++compilers implement tail-call optimization, and properly structuredtail-recursive functions are not limited by the stack size. The compilergenerates code that does not add a stack frame and will not exceed the stacklimit with a high number of recursive calls. This chapter covers recursive implementations of STLalgorithms, and most are implemented with tail-recursion. Some algorithmsinclude non-tail-recursive implementations for exposition or when they arefound to compile to code that will not exceed the stack. All of the functionsin this chapter were tested with a very large recursion depth, and noneresulted in a segmentation fault.

Most of the algorithms covered in this chapter arenon-modifying algorithms that will not modify the data processed by thealgorithm. These algorithms can process data accessed by const iterators that transformthe data without changing it. Iterative implementations of these algorithms areavailable for comparison at the website http://cplusplus.comhere: http://www.cplusplus.com/reference/algorithm/ http://www.cplusplus.com/reference/numeric/

all_of
The all_of algorithm returns true if all of the elements ofa sequence are true when individually passed to the unary predicate. Thisalgorithm checks each element until the predicate returns false or reaches theend of the sequence. Since the AND operator (&&) short-circuitsevaluation if the argument to the left of it is false, the all_of function on the right side of it willnot be called and the recursion will stop.
recursive::all_of
template< class InputIterator,class UnaryPredicate>bool all_of (InputIterator first,InputIterator last,UnaryPredicate pred){if (first == last) return true;return pred(*first)) &&all_of(std::next(first), last, pred);}
Most of the algorithms in this chapter start with aconditional statement that checks whether the end of the sequence has beenreached and the first and last iterator are equal.
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Functional Programming with C++»

Look at similar books to Functional Programming with C++. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Functional Programming with C++»

Discussion, reviews of the book Functional Programming with C++ and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.