lambda.mdwn 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. # Intro
  2. I made releases of SGP and Sif, and soon I'll get Tosaf ready for its first
  3. release. When that happens, the minimal C++ toolset needed for
  4. [[Release 0|/roadmap]] will be ready for first use. The next step will involve
  5. the semantic components, such as Dilosi and Saugus.
  6. For a while I've been considering to write them, and the system in general, in
  7. a functional language. Instead of C++ as I've been doing so far. Since the
  8. semantic components don't have much serious code yet, I want to examine the
  9. situation carefully make an educated decision. If I choose functional I'll use
  10. whatever conventions that language uses for module loading, error handling and
  11. so on.
  12. In this page I'm going to document my findings, thoughts and ideas. Functional
  13. languages, APIs, compilers and examples of existing software.
  14. # Info
  15. First, a list of functional programming languages I know.
  16. - Common Lisp
  17. - Emacs Lisp
  18. - Scheme
  19. - Racket
  20. - ML (?)
  21. - Haskell
  22. - Mercury (?) - logical with functional support
  23. Now let's start. What is functional programming?
  24. - [[!wikipedia Functional_programming]]
  25. - <https://he.wikipedia.org/wiki/תכנות_פונקציונלי>
  26. - [[!wikipedia Functional_logic_programming]]
  27. Languages:
  28. - [[!wikipedia Common_Lisp]]
  29. - [[!wikipedia Scheme_(programming_language) desc=Scheme]]
  30. - [[!wikipedia Clojure]]
  31. - [[!wikipedia Racket_(programming_language) desc=Racket]]
  32. - [[!wikipedia Erlang_(programming_language) desc=Erlang]]
  33. - [[!wikipedia OCaml]]
  34. - [[!wikipedia Standard_ML]]
  35. - [[!wikipedia Haskell_(programming_language) desc=Haskell]]
  36. - [[!wikipedia F_Sharp_(programming_language) desc=F#]]
  37. Functional style is also supported in or possible with:
  38. - [[!wikipedia Perl]]
  39. - [[!wikipedia PHP]] (especially/at least since 5.3)
  40. - [[!wikipedia C_Sharp_(programming_language) desc=C#]] 3.0
  41. - [[!wikipedia Java_programming desc=Java]] 8
  42. - [[!wikipedia Scala_(programming_language) desc=Scala]]
  43. - [[!wikipedia C++11]]
  44. - [[!wikipedia C++]] meta-programming with templates
  45. First thoughts:
  46. - Haskell is the most recent result of a standard for functional programming
  47. research, so it may be a good option.
  48. - Scheme is older, but compiled Scheme with all the needed libraries and access
  49. may work too.
  50. - I remember using OCaml programs such as Unison and some simple graph editor,
  51. so check OCaml too (and standard ML).
  52. - What are Clojure and Erlang and F#? Are they relevant?
  53. - Do I need functional logic? What does Mercury's code look like?
  54. - Go over these languages' pages and see what influenced them, what they
  55. influenced etc. as a way to find more interesting languages to examine
  56. - What about efficiecy? In general and specifically for working with a database
  57. like my case. Maybe write the DB in C/C++ and then everything else in
  58. functional?
  59. Findings:
  60. - For working with large arrays, multi dimensional DBs, etc. it seems that the
  61. J language and NumPy may peform better than the other options. But this is too
  62. early to optimize and perhaps conceptually wrong - why should a different
  63. style be chosen just because of super-low-level hardware design details? Also
  64. remember it's a personal system/desktop database, not a terabyte-huge one.
  65. Another option is to implement the trees, caches, etc. in C/C++ and then
  66. access them from functional style code.
  67. - [[!wikipedia Software_transactional_memory]] can help with the database access
  68. related part. A Haskell implementation exists.
  69. About languages - from Wikipedia:
  70. - Clojure: General-purpose programming language with an emphasis on functional
  71. programming. It runs on the Java Virtual Machine, Common Language Runtime, and
  72. JavaScript engines. Like other Lisps, Clojure treats code as data and has a
  73. macro system. Its focus on programming with immutable values and explicit
  74. progression-of-time constructs are intended to facilitate the development of
  75. more robust programs, particularly multithreaded ones.
  76. - Elixir: Functional, concurrent, general-purpose programming language built
  77. atop the Erlang Virtual Machine (BEAM). Elixir builds on top of Erlang to
  78. provide distributed, fault-tolerant, soft real-time, non-stop applications but
  79. also extends it to support metaprogramming with macros and polymorphism via
  80. protocols.
  81. - Erlang: General-purpose concurrent, garbage-collected programming language and
  82. runtime system. The sequential subset of Erlang is a functional language, with
  83. eager evaluation, single assignment, and dynamic typing. It was designed by
  84. Ericsson to support distributed, fault-tolerant, soft-real-time, non-stop
  85. applications. It supports hot swapping, so that code can be changed without
  86. stopping a system. While threads require external library support in most
  87. languages, Erlang provides language-level features for creating and managing
  88. processes with the aim of simplifying concurrent programming. Though all
  89. concurrency is explicit in Erlang, processes communicate using message passing
  90. instead of shared variables, which removes the need for explicit locks (a
  91. locking scheme is still used internally by the VM).
  92. - F#: Strongly typed, multi-paradigm programming language that encompasses
  93. functional, imperative, and object-oriented programming techniques. F# is most
  94. often used as a cross-platform CLI language, but can also be used to generate
  95. JavaScript and GPU code.
  96. - Haskell: Standardized, general-purpose purely functional programming language,
  97. with non-strict semantics and strong static typing.
  98. - Julia: High-level dynamic programming language designed to address the
  99. requirements of high-performance numerical and scientific computing while also
  100. being effective for general purpose programming. Distinctive aspects of
  101. Julia's design include having a type system with parametric types in a fully
  102. dynamic programming language, and adopting multiple dispatch as its core
  103. programming paradigm. It allows for parallel and distributed computing, and
  104. direct calling of C and Fortran libraries without glue code. Julia is garbage
  105. collected by default and unlike other functional languages that use lazy
  106. evaluation Julia uses eager evaluation (with the package Lazy.jl providing
  107. "cornerstones of functional programming - lazily-evaluated lists and a large
  108. library of functions for working with them") and includes efficient libraries
  109. for floating point, linear algebra, random number generation, fast Fourier
  110. transforms, and regular expression matching.
  111. - Mercury: Functional logic programming language geared towards real-world
  112. applications. It was initially developed at the University Of Melbourne
  113. Computer Science department under the supervision of Zoltan Somogyi. The first
  114. version was developed by Fergus Henderson, Thomas Conway and Zoltan Somogyi
  115. and was released on April 8, 1995. Mercury is a purely declarative logic
  116. language. It is related to both Prolog and Haskell. It features a strong,
  117. static, polymorphic type system, as well as a strong mode and determinism
  118. system.
  119. - OCaml: ML-derived languages are best known for their static type systems and
  120. type-inferring compilers. OCaml unifies functional, imperative, and
  121. object-oriented programming under an ML-like type system. This means the
  122. program author is not required to be overly familiar with pure functional
  123. language paradigm in order to use OCaml. OCaml features: a static type system,
  124. type inference, parametric polymorphism, tail recursion, pattern matching,
  125. first class lexical closures, functors (parametric modules), exception
  126. handling, and incremental generational automatic garbage collection.
  127. - Scala: Object-functional programming language for general software
  128. applications. Scala has full support for functional programming and a very
  129. strong static type system. This allows programs written in Scala to be very
  130. concise and thus smaller in size than other general purpose programming
  131. languages. Many of Scala's design decisions were inspired by criticism over
  132. the shortcomings of Java. Scala source code is intended to be compiled to Java
  133. bytecode, so that the resulting executable code runs on a Java virtual
  134. machine. Java libraries may be used directly in Scala code, and vice versa.
  135. Like Java, Scala is object-oriented, and uses a curly-brace syntax reminiscent
  136. of the C programming language. Unlike Java, Scala has many features of
  137. functional programming languages like Scheme, Standard ML and Haskell,
  138. including currying, type inference, immutability, lazy evaluation, and pattern
  139. matching. It also has an advanced type system supporting algebraic data types,
  140. covariance and contravariance, higher-order types, and anonymous types. Other
  141. features of Scala not present in Java include operator overloading, optional
  142. parameters, named parameters, raw strings, and no checked exceptions.
  143. - Ruby: Dynamic, reflective, object-oriented, general-purpose programming
  144. language. According to its authors, Ruby was influenced by Perl, Smalltalk,
  145. Eiffel, Ada, and Lisp. It supports multiple programming paradigms, including
  146. functional, object-oriented, and imperative. It also has a dynamic type system
  147. and automatic memory management.
  148. - Rust: General purpose, multi-paradigm, compiled programming language developed
  149. by Mozilla Research. It is designed to be a "safe, concurrent, practical
  150. language", supporting pure-functional, concurrent-actor,
  151. imperative-procedural, and object-oriented styles. The goal of Rust is to be a
  152. good language for the creation of large client and server programs that run
  153. over the Internet. This has led to a feature set with an emphasis on safety,
  154. control of memory layout and concurrency. Performance of safe code is expected
  155. to be slower than C++ if performance is the only consideration, but to be
  156. comparable to C++ code that manually takes precautions comparable to what the
  157. Rust language mandates.
  158. - Scheme: Functional programming language and one of the two main dialects of
  159. the programming language Lisp. Unlike Common Lisp, the other main dialect,
  160. Scheme follows a minimalist design philosophy specifying a small standard core
  161. with powerful tools for language extension.
  162. What sounds good, after reading:
  163. - Haskell
  164. - OCaml
  165. - Scheme
  166. Also, it looks like there are many languages I can use in place of C++. For
  167. example Go. But first, let's understand the nature of the problem. How do
  168. databases even work? What is Software Transactional Memory, and do databases use
  169. it? *Can* they use it? How does my query model work exactly and how queries can
  170. be efficiently executed? Before I can provide good answers, here are the tasks:
  171. - Understand better how DBs work by reading (e.g. my DB course slides)
  172. - Look at the source code of:
  173. + SQLite
  174. + 4store
  175. + Redland
  176. + Haystack (unlike the rest, this is semantic desktop per definition)
  177. - Understand better my requirements and make progress with Smaoin and Naya
  178. Before that I'd like to make a first release of [[/projects/Tosaf]].
  179. # Learning Haskell
  180. There are several good Haskell learning books on the web, but not all of them
  181. are free culture works. Money is driving some people to use NC licenses. I
  182. wonder if selling a book makes more profit than taking donations for a free
  183. culture book. Anyway, the point is we want to support free culture! Three of
  184. the common licenses for free culture works are:
  185. - CC by (requires just attribution, somewhat like BSD/MIT for software)
  186. - CC by-sa (also requires share-alike, somewhat like GPL for software)
  187. - CC0 (which is basically public domain)
  188. Here are resources I checked which are free culture work and you can learn
  189. Haskell using them (or ask people to liberate their nonfree work):
  190. - Haskell wikibook
  191. I'm collecting useful links and other info while learning Haskell and making
  192. first steps. See [[here|/people/fr33domlover/haskell]].