Functional Programming in C First Edition Ivan Cukic instant download
Functional Programming in C First Edition Ivan Cukic instant download
Cukic download
https://ebookultra.com/download/functional-programming-in-c-
first-edition-ivan-cukic/
https://ebookultra.com/download/real-world-functional-programming-
with-examples-in-f-and-c-1st-edition-tomas-petricek/
https://ebookultra.com/download/functional-programming-in-python-1st-
edition-david-mertz/
https://ebookultra.com/download/programming-concepts-in-c-2nd-edition-
robert-burns/
https://ebookultra.com/download/programming-in-c-2-e-second-edition-
dey/
Memory as a Programming Concept in C and C Frantisek
Franek
https://ebookultra.com/download/memory-as-a-programming-concept-in-c-
and-c-frantisek-franek/
https://ebookultra.com/download/c-programming-in-linux-1st-edition-
edition-haskins-d/
https://ebookultra.com/download/object-oriented-programming-in-c-4th-
edition-e-balagurusamy/
https://ebookultra.com/download/programming-microcontrollers-in-c-2nd-
ed-edition-ted-vansickle/
https://ebookultra.com/download/concepts-in-programming-languages-1st-
edition-john-c-mitchell/
Functional Programming in C First Edition Ivan Cukic
Digital Instant Download
Author(s): Ivan Cukic
ISBN(s): 9781617293818, 1617293814
Edition: First Edition
File Details: PDF, 10.54 MB
Year: 2018
Language: english
MANNING
Functional Programming in C++
Functional Programming
in C++
IVAN ČUKIĆ
MANNING
Shelter Island
For online information and ordering of this and other Manning books, please visit www.manning.com.
The publisher offers discounts on this book when ordered in quantity.
For more information, please contact
Special Sales Department
Manning Publications Co.
20 Baldwin Road
PO Box 761
Shelter Island, NY 11964
Email: orders@manning.com
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form
or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the
publisher.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed
as trademarks. Where those designations appear in the book, and Manning Publications was aware of a
trademark claim, the designations have been printed in initial caps or all caps.
∞ Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books
we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our
responsibility to conserve the resources of our planet, Manning books are printed on paper that is at
least 15 percent recycled and processed without the use of elemental chlorine.
ISBN 9781617293818
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 – SP – 23 22 21 20 19 18
brief contents
1 ■ Introduction to functional programming 1
2 ■ Getting started with functional programming 21
3 ■ Function objects 45
4 ■ Creating new functions from the old ones 71
5 ■ Purity: Avoiding mutable state 100
6 ■ Lazy evaluation 122
7 ■ Ranges 142
8 ■ Functional data structures 158
9 ■ Algebraic data types and pattern matching 174
10 ■ Monads 199
11 ■ Template metaprogramming 226
12 ■ Functional design for concurrent systems 248
13 ■ Testing and debugging 274
v
contents
preface xiii
acknowledgments xv
about this book xvii
about the author xxi
vii
viii contents
3 Function objects
3.1
45
Functions and function objects
Automatic return type deduction 46 Function
46
■
std::bind 83
application 90
contents ix
6 Lazy evaluation
6.1 Laziness in C++
122
123
6.2 Laziness as an optimization technique 126
Sorting collections lazily 126 Item views in the user
■
7 Ranges 142
7.1 Introducing ranges 144
7.2 Creating read-only views over data 145
Filter function for ranges 145 Transform function for
■
the bitmapped vector trie 171 Other operations and the overall
■
10 Monads 199
10.1 Not your father’s functors
Handling optional values 201
200
11 Template metaprogramming
11.1 Manipulating types at compile-time
226
types 234
index 287
preface
Programming is one of the rare disciplines in which you can create something from
absolutely nothing. You can create whole worlds that behave exactly as you want them
to behave. The only thing you need is a computer.
When I was in school, most of my programming classes focused on imperative program-
ming—first on procedural programming in C, and then on object-oriented pro-
gramming in C++ and Java. The situation didn’t change much at my university—the
main paradigm was still object-oriented programming (OOP).
During this time, I almost fell into the trap of thinking that all languages are con-
ceptually the same—that they differ only in syntax, and that after you learn the basics
such as loops and branching in one language, you can write programs in all others with
minor adjustments.
The first time I saw a functional programming language was at the university, when I
learned LISP in one of my classes. My gut reaction was to use LISP to simulate if-then-
else statements and for loops so that I could actually make it useful. Instead of trying
to change my perspective to fit the language, I decided to bend the language to allow
me to write programs in the same way I used to write them in C. Suffice it to say that back
then, I saw no point whatsoever in functional programming—everything I could do
with LISP, I could do with C much more easily.
It took a while before I started looking into FP again. The reason I did was that I was
disappointed by the slow evolution of one particular language that I was required to use
while working on a few projects. A for-each loop was added to the language, and it was
advertised as if it were a huge deal: you just had to download the new compiler, and your
life would become much easier.
xiii
Random documents with unrelated
content Scribd suggests to you:
HEROINES OF NATIONAL
PROGRESS
ELIZABETH CADY STANTON AND SUSAN B.
ANTHONY, TWO PIONEERS IN THE CAUSE OF
WOMAN'S SUFFRAGE
215. The Women of Our Nation. Women have
had a large part in the progress of our nation. In Women play an
important part
colonial days women often had to defend their in early
homes against Indians. They endured the progress
hardships of the first settlements as bravely as did
the men. They had larger rights and greater freedom than in
England at that time, because their help was so plainly necessary in
this new country.
By 1850 nearly one-fourth of the nation's manufacturing was done
by women, but otherwise until that time women's lives were spent
almost entirely in their homes. Though no colleges were open to
women until 1833, many mothers knew enough of books to prepare
their sons for college at home.
During the Revolution women formed a society
called "Daughters of Liberty," to spin and sew for Women's
service in war
their soldiers. They gave their treasured pewter
spoons and dishes to be melted up for bullets. As women have
always done, they cared for the sick and wounded after battles.
ELIZABETH CADY STANTON
From a photograph
In the great Civil War, women were needed still more to nurse the
wounded, for even then there was no Red Cross or large body of
women who were nurses by profession to call upon. Women took
the place of the men called to war in many ways, and especially in
teaching schools. On both sides women worked in the fields, and
sometimes acted as spies, or served, disguised, in the ranks.
Southern women also entered the factories in large numbers. They
had to meet even greater hardship than women in the North, and
were often face to face with starvation.
On the frontier women had always worked in the fields when
necessary, and often helped to build the houses they lived in. The
fearless pioneering spirit and fine, sturdy character of these women
won them the highest respect. This was one reason why western
states were the first to grant women the right to vote.
Long before the Civil War great leaders in the
cause of woman's advancement had appeared. Women's
equality with
These leaders saw that in many ways women had men
proved their equality with men. This encouraged
them to appeal for wider opportunities for women, who then had
almost no legal rights. The leaders now demanded the privileges
enjoyed only by men. We should all know the stories of these
women of wise and fearless vision.
216. Elizabeth Cady Stanton. Elizabeth Cady
was born in New York, in 1815. Her girlhood was a Born, 1815
happy one, spent with her brother and sisters. She
was a healthy, rosy-cheeked girl, full of life and fun, who believed
girls were the equals of boys and had just as much intellect.
When Elizabeth was eleven years old her brother
died. Her father grieved deeply over the loss of his Studies hard
only son, and Elizabeth determined to try to be to
her father all that her brother might have been. She therefore
applied herself diligently to study and self-improvement.
Her father was a lawyer. He had been a member of
Congress. Many hours out of school Elizabeth spent Finds woman's
position
in his office, listening while his clients stated their unequal
cases. She gradually became indignant at what she
found to be the unequal position of women in almost every walk of
life. She determined to devote her life to securing for women the
same rights and privileges that men had.
While studying she did not neglect the arts of
housekeeping. She regarded these as occupations Marries Henry
B. Stanton
of the highest dignity and importance. When
twenty-five years old she married Henry B. Stanton, a lawyer and
journalist who since his student days had talked and written against
slavery. But she did not forget her old resolve to struggle for the
rights of women, even when occupied with the duties of home and
children.
217. The First Woman's Rights Convention.
In 1848 Mrs. Stanton called a woman's rights Calls woman's
rights
convention—the first ever held. Its purpose was "to convention
discuss the social, civil, and religious conditions and
rights of women."
Mrs. Stanton read to the convention a set of twelve
resolutions, the now famous "Declaration of "Declaration of
Sentiments"
Sentiments." It demanded for women equality with
men and "all the rights and privileges which belong
to them as citizens of the United States," including Women
demand the
the right to vote. This was the first public demand right to vote
for woman's suffrage. The resolutions were passed.
A storm of ridicule followed the convention, but Mrs. Stanton's
position remained unchanged.
SUSAN B. ANTHONY
From a photograph by Veeder, Albany, N.Y.
218. Susan B. Anthony. A few years after this
historic convention, Mrs. Stanton met Susan B. Susan B.
Anthony, 1820
Anthony. Miss Anthony was the daughter of
Friends, or Quakers as they are often called. She was born at South
Adams, Massachusetts, in 1820. Her father maintained a school at
Battenville, New York, and here Susan received her early education.
From her seventeenth birthday until she met Mrs.
Stanton, Miss Anthony had been engaged in Teaches school
teaching school. But now the great national
questions of anti-slavery and temperance were
drawing her away from her work as a teacher. At Won to the
cause of
first Miss Anthony had not been in sympathy with woman's rights
the Declaration of Sentiments, but when she met
Mrs. Stanton the cause of woman's rights won an able, enthusiastic,
and untiring friend.
From this time on these two fought side by side for
the cause of women. They traveled and lectured in National
Woman's
all parts of the country. In 1868 they started a Suffrage
weekly paper, which they called The Revolution. Association
Miss Anthony was the business manager and Mrs.
Stanton was the editor. Its motto was, "The True Republic—men,
their rights and nothing more; women, their rights and nothing less."
In 1869 they organized the National Woman's
Suffrage Association. In many states the question Miss Anthony
casts vote for
of woman suffrage became an important one at President
election. Wherever they were needed, in California,
in New York, or in any other state, these two women could be found.
Every year from 1869 until her death, in 1906, Miss Anthony
addressed committees of Congress. In 1872 she cast a vote for
President. She declared it to be her right under the Fourteenth
Amendment to the Constitution. For this act she was arrested and
fined, but the fine was never collected.
Mrs. Stanton died in 1902. The great movement
she had started was on its way to certain victory. Women win
suffrage
Congress passed the suffrage amendment in 1919,
and in August, 1920, it became law. Over twenty-five million women
were entitled to vote in the presidential elections that year.
JULIA WARD HOWE, AUTHOR OF THE "BATTLE
HYMN OF THE REPUBLIC," AND HARRIET
BEECHER STOWE WHO WROTE "UNCLE TOM'S
CABIN"
219. Julia Ward Howe. All the great wars in which our country
has engaged have brought heavy burdens and sorrow to women.
They could not march away to fight side by side with the men. Their
duty was to cheer their loved ones as they went away to danger and
perhaps to death.
At the outbreak of the Civil War, from thousands
and thousands of homes father, husband, son, or Women in the
Civil War
brother went away, in many instances never to
return. Women were left behind, praying for their loved ones and
working untiringly night and day to provide food and clothing and to
keep up their homes.
But there were other women who could not serve
their country in this way. Many had no one to send Born 1819
away to fight. Among these was Julia Ward Howe.
She was born in New York in 1819, of wealthy and distinguished
parents. She was carefully reared, but she knew little of the work
that girls are usually taught to do. Practically everything was done
for her by servants. However, Julia dearly loved to read and study,
and very early she began to write poetry.
In 1841 she married Dr. Samuel Gridley Howe, a
noted teacher and reformer. While visiting in Marries Doctor
Howe
Washington in 1861 she saw women nursing the
wounded soldiers brought in from the battle field of
Desires to be of
Bull Run. She was deeply stirred by the sights service to the
around her. What service could she do for her Union
country? Her husband was too old to enter the
army, her son too young. She knew that there were thousands
making clothes for the soldiers in the field. But she could not sew for
the soldiers or care for the wounded, for she had never been taught
to work with her hands. She could only write poetry. Of what use
was that now?
One day her minister suggested that she write
words for the popular army tune, "John Brown's Writes "Battle
Hymn of the
Body Lies A-mouldering in the Grave." She did so, Republic"
and the poem was published in a magazine under
the name of "The Battle Hymn of the Republic."
Soon the song was being sung through all the
camps of the northern troops. The soldiers sang it It helps to bring
victory
on the march, in wild charges, or at night beside
the camp fire. Everywhere its challenge roused the northern soldiers
to a more determined fight for victory. In writing this poem Mrs.
Howe had done a great service for the Union.
JULIA WARD HOWE
From a photograph by the Notman Photo. Co.,
Boston
220. The Woman's Club. After the war Mrs.
Howe wished to continue serving her country in Founds clubs
for women
some way, and she took up the cause of woman's
rights. Women had had little or no chance to educate themselves
and broaden their minds by discussing with each other subjects
outside their homes. She thought woman's clubs would work to free
women from the narrowness of mind that comes from thinking only
of dress, hired help, and housekeeping. From then on, she devoted
herself to establishing clubs for women. She traveled over the
country and wrote and lectured on this subject. She urged that the
members of these clubs should seek not only for self-improvement
but for means of serving others; and through their efforts hospitals
for women and children, lodging houses, and labor schools were
established.
Mrs. Howe had found a means of serving her country even greater
and more effective than the writing of her "Battle Hymn of the
Republic."
221. Harriet Beecher Stowe. Another woman
who did great service for her country with her pen Born, 1811
was Harriet Beecher Stowe. She was born in 1811.
Her father was a Connecticut minister, and she was brought up in a
deeply religious home. At school she was apt at writing and she
dreamed of becoming a great author.
She married Calvin E. Stowe, a student of theology,
and thereafter devoted herself to her home and Marries Calvin
E. Stowe
her children. During the years just before the Civil
War there was much discussion of the slavery question. Mrs. Stowe
had traveled in the South and had seen how the negroes were kept
in ignorance, and how cruelly they were sometimes treated. She was
aroused by the passage of the Fugitive Slave Law and by some of
the things that happened as a result of it. She resolved to use her
talent for writing to help the slaves.
In 1851 she began the story, Uncle Tom's Cabin. It
was first published in serial form in an abolition Writes "Uncle
Tom's Cabin"
paper in Washington. It was later published in book
form. From the first, the sale of the book was enormous. It was
translated into many languages and was very popular abroad as well
as at home.
HARRIET BEECHER STOWE
From a photograph by Sarony, New York
Mrs. Stowe became famous. It is said that the book converted more
than two million people to the cause of freedom for slaves. It helped
to unite the North and to give it strength to stand firm in the great
conflict.
Mrs. Stowe continued writing in behalf of the slaves. She gave her
son to the cause of freedom. He was wounded at Gettysburg and
never regained his health. She aided in establishing schools for the
negroes in the South, and worked among them earnestly until her
death in 1896.
FRANCES E. WILLARD, THE GREAT
TEMPERANCE CRUSADER; CLARA BARTON,
WHO FOUNDED THE RED CROSS SOCIETY IN
AMERICA; AND JANE ADDAMS, THE FOUNDER
OF HULL HOUSE SOCIAL SETTLEMENT IN
CHICAGO
222. Frances E. Willard. In 1839, when Frances
Elizabeth Willard was born, thousands were leaving Frances E.
Willard, 1839
the eastern states for the new West. Her father
and mother were successful teachers in New York,
but when Frances was two years old they decided Family
moves
to Wisconsin
to move with the westward current. After living five
years at Oberlin, Ohio, the family went on to Janesville, Wisconsin,
settling on a farm in the midst of picturesque hills and woods. There
Frances and her brother and sister grew up healthy, happy children,
playing together in the forest and fields. The parents were religious
and were total abstainers, and the children never forgot their
teachings.
At fifteen years of age Frances went to school in
Janesville, and at eighteen to a Milwaukee college Stands at head
of her class
for girls. The following year she entered the
Northwestern Female College at Evanston, Illinois. At graduation she
stood at the head of her class.
Miss Willard began teaching. Then the death of her
sister Mary, and shortly afterward, of her father, Death breaks
up the home
broke up her home. That home had been an ideal
one. There the father and mother were equal in all things, and
discussed together the affairs of the household. It was a perfect
home, orderly and temperate. Frances Willard made up her mind to
spend her life in spreading abroad a knowledge of such homes, and
in helping women to become equal with men before the law.
FRANCES E. WILLARD
From a photograph
In 1874 came the anti-saloon crusade. Miss Willard
saw that this movement was part of the fight for President of
W.C.T.U.
better and happier homes, and threw herself
ardently into the work. When the Woman's Christian Temperance
Union was organized in Chicago, Miss Willard became its president.
In 1879 she became the president of the National Union. Her work
was never-ending. She wrote books; she lectured all over the
country. For twelve years she held an average of one meeting a day.
Miss Willard had seen that unless women had the
right to assist in making laws, their cause was Favors woman
suffrage
hopeless. Accordingly she declared herself in favor
of woman suffrage. A few years later the Woman's Christian
Temperance Union followed their leader into politics in an effort to
encourage temperance legislation.
Miss Willard's work constantly became wider. The
organization of which she was the head became Women united
for the
international in its influence, and the World's protection of
Woman's Christian Temperance Union was the home
organized in 1883, with Miss Willard as president.
She had united the women of the world in a great league for the
protection of the home. Miss Willard remained to the end of her life
president of the World's Woman's Christian Temperance Union. She
died in 1898.
CLARA BARTON
From a photograph by Charles E. Smith,
Evanston, Illinois
223. Clara Barton. Clara Barton was born in
1821, near Oxford, Massachusetts. She was Clara Barton,
1821
educated to be a school teacher, and for many
years followed that profession. In 1861 she visited Washington, and
there felt the impulse that led to her great life work.
The injured soldiers from the first battles of the
Civil War were being brought to Washington. Miss Nurses the
wounded
Barton at once felt it her duty to help in caring for
them. She not only nursed the wounded, but she encouraged those
who were on the way to the line of battle.
224. Goes to the Battle Field. The men that were being taken to
the hospitals received no care until they arrived there. Miss Barton
saw that her place was on the battle field.
She secured a pass to the firing line, and for four
years she followed the Union soldiers. She was Constantly in
danger
constantly in danger; her clothing was pierced by
bullets, her face blackened by powder. But she was
undaunted. The soldiers needed her, and she must Received
pay
no
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com