Learning F#: What books using other programming la

2020-08-26 03:21发布

问题:

I am now several months into learning F# with the greatest asset for learning F# being translating the OCaml code in "Handbook of Practical Logic and Automated Reasoning" (WorldCat) by John Harrison, into F#.

With this being such an effective method of learning, I plan to translate the code in more books to F#, but books primarily focused on functional concepts or real world applications typically known for being written with a functional language such as AI, compilers, Theorem Provers and Reasoning Assistants.

While one would think that translating a program from one language to another might be a trivial task, in reality when doing such one runs into differences not only in the language but the environment and tools that must also be learnt and understood to do the translation. One is required to explore the depths of both languages and their environments that are not typically considered when just reading about it. For example in translating Ocaml to F# I learned top-level, ocamldebug and time travel, trace and wishing F# had this, camlp4 and how it doesn't exist in F#, exception handling performance differences, and type inference in a manner that forced me to understand the F# counterparts in ways I would not have by just experimenting or reading books with F#.

Do you know of any other books that use/include source code, preferably functional, that cover concept(s) of functional programming or are real world applications typically written in a functional language and that will help in learning functional programming by translating the source code to F#?

To keep this objective and not subjective, the answers must explain why it is important, and you must have used the book not just browsed the book. I am looking for answers from people who have been doing functional programming for years and have found working through such a book a key to their success with functional programming. Examples of answers:

  • Type inference - "Types and Programming Languages" (WorldCat) by Benjamin C. Pierce. Importance: Helps to understand how to resolve type inference compiler errors which leads to better ways to resolve the error and results in better code.

  • CPS - "Compiling with Continuations" (WorldCat) by Andrew W. Appel – Importance: Helps to remove the use of a stack in recursion and thus stack overflows and improve performance. I think of tail-call optimization as optimizing a function and CPS as optimizing the program.

  • Term rewriting - "Term Rewriting and All That" (WoldCat) by Franz Baader and Tobias Nipkow Importance: With ATP and Proof assistants typically being written using a functional language and relying on term rewriting, if the term rewriting is incorrect then the proof engine is invalid.

  • Lambda Calculus - "An Introduction To Functional Programming Through Lambda Calculus" (WorldCat) by Greg Michaelson Importance: Lambda calculus is the basis of functional programming. Understanding this basic concept leads to a better understanding of functional programing.

EDIT

While I would like to hold off and wait for a better answer to accept, I have learned that after a few days on SO the views tail off considerably.

I find that both answers are great for anyone not familiar with the books and that if I didn't already know and have copies of most of the books I would seriously consider getting them.

Since PAD noted the more advanced books which is what I was after, I give him the accept vote. If could split the accept I would.

回答1:

You list looks so scary to me. I suggest a few more fundamental ones:

  1. Purely functional data structures book by Okasaki. The book uses SML notations; translating its examples into F# is challenging due to the lack of functors. But the benefit is huge; you will learn a lot during the process and on the other hand help F# community tremendously. As @Jack P. mentioned, many of these data structures have been ported to F#; they could be a great start for you.

  2. ML for the Working Programmer by Paulson. I particularly like the part of using induction to prove correctness of programs. A few big examples in the book such as Writing interpreters for the lambda-calculus and A tactical theorem prover are interesting and close to your domain of interest.

  3. The Haskell School of Expression by Hudak. This book will give you very fun time and sense of achievement since you finish it with real-world and exciting applications. Moreover, there is a lot of useful information about designing DSLs in the book.

I really admire your persistence of learning F# through trial-and-error process. If you could survive after John Harrison's book, I think very few ones will look challenging to you. I would recommend you to find a real application in another functional language, which we don't have in F# and port it. For instance, from the book's examples, writing a simple proof assistant in F# similar to Coq, Isabelle or Hol-light is not so far.



回答2:

Considering the titles listed in your question you are already far ahead of basics. But talking of fundamentals I'd suggest considering:

Richard Bird, Philip Wadler - Introduction to Functional Programming, 1st Ed ISBN:0134841891 (book's FP language is Miranda)

and all-times classic

Harold Abelson and Gerald Jay Sussman - Structure and Interpretation of Computer Programs, 2nd Ed ISBN:0262011530 (book's FP language is Scheme)