Lazy Interworking of Compiled and Interpreted Code for Sandboxing and Distributed Systems

Total Page:16

File Type:pdf, Size:1020Kb

Lazy Interworking of Compiled and Interpreted Code for Sandboxing and Distributed Systems Lazy Interworking of Compiled and Interpreted Code for Sandboxing and Distributed Systems Camil Staps August 16, 2019 Supervisor: prof. dr. dr.h.c. ir. M.J. Plasmeijer Second reader: drs. J.H.G. van Groningen Contents Preface 5 1 Paper to be presented at IFL '19 7 2 File types and bytecode generation workflow 19 2.1 Bytecode generation . 19 2.2 Options in the Clean IDE and cpm ........................ 20 2.3 File formats . 21 2.3.1 Bytecode (.bc)............................... 21 2.3.2 Prelinked bytecode (.pbc)......................... 22 3 Building the source 25 3.1 Source code overview . 25 3.2 Build workflow . 25 3.2.1 Bytecode generation toolchain . 25 3.2.2 Library object files . 26 3.2.3 Standalone interpreter . 26 3.2.4 Graphical debugger . 26 3.2.5 WebAssembly interpreter . 26 3.3 32-bit builds . 27 4 Future work 29 4.1 Safe interpretation in Soccer-Fun . 29 4.2 A JavaScript debugger . 29 4.3 The Clean compiler in the browser . 30 4.4 End-to-end tests for iTasks with Selenium . 30 3 Preface This thesis is the result of approximately one and a half year of work on the development of an interpreter for the lazy functional programming language Clean and its application in various contexts. As will be explained below, interpretation is done on the level of the intermediate language for the abstract ABC machine. When I became involved in the project, John van Groningen had already written a 32- bit ABC interpreter targeting C and asm.js with near-complete support for the entire ABC instruction set. With Erin van der Veen, I developed a 64-bit version of the C interpreter and started to put it to use to communicate lazy values between different binaries and platforms. Because the evaluation of a lazy value may depend on program code which may not be present in the receiving executable, the interpreter is here used to make the communication platform-independent (although other options, like just-in-time compilation combined with dynamic linking, would have been suitable as well). Interworking of compiled and interpreted code was in a very early stage when the project with Erin van der Veen finished and was finalized only at the end of my research internship. As my master's thesis project, I then ported the interpreter to WebAssembly and applied it in the iTasks framework for developing workflow web applications. This framework needs a way to run Clean in web browsers and interact with the Document Object Model (DOM) of the web page as well as with third-party JavaScript libraries. Previously, this frame- work used just-in-time compilation to JavaScript, but our new setup with an interpreter in WebAssembly yields a more predictable and overall better performance. Summarizing, this thesis describes three main deliverables: • A standalone (C) interpreter, with a suitable bytecode format and the accompanying toolchain (bytecode generator, linker, and stripper). • A Clean \serialization" library capable of (de)serializing lazy values in a platform-in- dependent and executable-agnostic manner. • A new backend for the browser interface of iTasks, together with a JavaScript foreign function interface. The noteworthy aspects of each of these have been described in detail in an article ac- cepted for presentation at the 2019 edition of Implementation and Application of Functional Languages (IFL). A preliminary version of this article constitutes the first and main chapter of this thesis. References are included in the paper and will be omitted in the rest of the thesis. The remainder of this thesis is more useful as a guide to using and further develop- ing the software described here: chapter 2 describes the bytecode generation workflow, IDE options, and file types; chapter 3 how the tools in the project can be built. In chapter 4 I give a number of ideas for future projects. I am deeply grateful for John's gladness to explain the finest details of the implementation of Clean and for Rinus' continuous watch on possibly related projects and application areas, for their overall supervision and the great amount of freedom they let me have. 5 6 Chapter 1. Paper to be presented at IFL '19 7 Lazy Interworking of Compiled and Interpreted Code for Sandboxing and Distributed Systems Camil Staps John van Groningen Rinus Plasmeijer [email protected] [email protected] [email protected] Radboud University Nijmegen Radboud University Nijmegen Radboud University Nijmegen Nijmegen, The Netherlands Nijmegen, The Netherlands Nijmegen, The Netherlands ABSTRACT KEYWORDS More and more applications rely on the safe execution of untrusted interpreters, functional programming, laziness, sandboxing, Web- code, for example in the implementation of web browsers and Assembly plugin systems. Furthermore, these applications usually require some form of communication between the untrusted code and its ACM Reference Format: embedder, and hence a communication channel must be set up Camil Staps, John van Groningen, and Rinus Plasmeijer. 2020. Lazy Inter- in which values are serialized and deserialized. This paper shows working of Compiled and Interpreted Code for Sandboxing and Distributed that in a functional programming language we can solve these Systems. In Proceedings of International Symposium on Implementation and two problems at once, if we realize that the execution of untrusted Application of Functional Languages (IFL’19). ACM, New York, NY, USA, code is nothing more than the deserialization of a value which 12 pages. https://doi.org/10.1145/nnnnnnn.nnnnnnn happens to be a function. To demonstrate this, we describe the implementation of a serialization library for the language Clean, which internally uses an interpreter to evaluate untrusted code in a separate, sandboxed environment. Remarkable is that despite 1 INTRODUCTION the conceptual asymmetry between “host” and “interpreter”, lazy The execution of untrusted code, or code that is unknown to the interworking must be implemented in a highly symmetric fashion, executable when it is started, has become paramount in a large much akin to distributed systems. The library interworks on a low number of different contexts. The most common example isthe level with the native Clean program, but has been implemented web browser, which has to be able to run JavaScript code (or more without any changes to the native runtime system. It can therefore recently WebAssembly [14]) which can interact with the web page easily be ported to other programming languages. but should under no circumstance crash the browser or the render- We can use the same technique in the context of the web, where ing engine. we want to be able to share possibly lazy values between a server Another use case can be found in plugin systems. We may for and a client. In this case the interpreter runs in WebAssembly in example imagine a compiler which can load plugins for various the browser and communicates seamlessly with the server, written language extensions, where plugins can provide functions for trans- in Clean. We use this in the iTasks web framework to handle com- forming the abstract syntax tree. In this case it is less important munication and offload computations to the client to reduce stress that plugins cannot crash the host program, but the plugin has to on the server-side. Previously, this framework cross-compiled the interwork on a much more fine-grained level with the host program, Clean source code to JavaScript and used JSON for communication. interacting closely with the same data types. The interpreter has a more predictable and better performance, and A similar need is felt in workflow systems like the iTasks frame- integration is much simpler because it interworks on a much lower work for Task-Oriented Programming [24, 25]. Applications written level with the web server. in this framework center around various tasks and the workflows that users walk through to execute them. Currently, applications CCS CONCEPTS must be recompiled to add new possible workflows. However, if • Software and its engineering → Functional languages; • In- we could dynamically add code to a running executable, the iTasks formation systems → Browsers; • Computer systems organi- server could remain online. zation → Client-server architectures. In many of these contexts, we furthermore want the “untrusted code” or the “plugin” to be able to be distributed in a platform- independent manner: there are no different JavaScript versions for different binary platforms, nor would one expect to have to Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed download a different compiler plugin on Windows than on Linux. for profit or commercial advantage and that copies bear this notice and the full citation This complicates the matter, because it means we cannot simply on the first page. Copyrights for components of this work owned by others than ACM distribute machine code which can be linked dynamically. must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a Lastly, in a lazy functional programming language, we expect fee. Request permissions from [email protected]. that the interface between the host program and the added code is IFL’19, September 2020, Singapore lazy as well. For instance, it should in principle be possible to have © 2020 Association for Computing Machinery. ACM ISBN 978-x-xxxx-xxxx-x/YY/MM...$15.00 a plugin in some system which computes an infinite list of integers, https://doi.org/10.1145/nnnnnnn.nnnnnnn as long as the host only requests a finite amount of them. 8 Chapter 1. Paper to be presented at IFL '19 IFL’19, September 2020, Singapore Camil Staps, John van Groningen, and Rinus Plasmeijer 1.1 The solution in a nutshell a web application are usually written in different languages.
Recommended publications
  • CSCI 2041: Lazy Evaluation
    CSCI 2041: Lazy Evaluation Chris Kauffman Last Updated: Wed Dec 5 12:32:32 CST 2018 1 Logistics Reading Lab13: Lazy/Streams I Module Lazy on lazy Covers basics of delayed evaluation computation I Module Stream on streams A5: Calculon Lambdas/Closures I Arithmetic language Briefly discuss these as they interpreter pertain Calculon I 2X credit for assignment I 5 Required Problems 100pts Goals I 5 Option Problems 50pts I Eager Evaluation I Milestone due Wed 12/5 I Lazy Evaluation I Final submit Tue 12/11 I Streams 2 Evaluation Strategies Eager Evaluation Lazy Evaluation I Most languages employ I An alternative is lazy eager evaluation evaluation I Execute instructions as I Execute instructions only as control reaches associated expression results are needed code (call by need) I Corresponds closely to I Higher-level idea with actual machine execution advantages and disadvantages I In pure computations, evaluation strategy doesn’t matter: will produce the same results I With side-effects, when code is run matter, particular for I/O which may see different printing orders 3 Exercise: Side-Effects and Evaluation Strategy Most common place to see differences between Eager/Lazy eval is when functions are called I Eager eval: eval argument expressions, call functions with results I Lazy eval: call function with un-evaluated expressions, eval as results are needed Consider the following expression let print_it expr = printf "Printing it\n"; printf "%d\n" expr; ;; print_it (begin printf "Evaluating\n"; 5; end);; Predict results and output for both Eager and Lazy Eval strategies 4 Answers: Side-Effects and Evaluation Strategy let print_it expr = printf "Printing it\n"; printf "%d\n" expr; ;; print_it (begin printf "Evaluating\n"; 5; end);; Evaluation > ocamlc eager_v_lazy.ml > ./a.out Eager Eval # ocaml’s default Evaluating Printing it 5 Lazy Eval Printing it Evaluating 5 5 OCaml and explicit lazy Computations I OCaml’s default model is eager evaluation BUT.
    [Show full text]
  • Reversible Programming with Negative and Fractional Types
    9 A Computational Interpretation of Compact Closed Categories: Reversible Programming with Negative and Fractional Types CHAO-HONG CHEN, Indiana University, USA AMR SABRY, Indiana University, USA Compact closed categories include objects representing higher-order functions and are well-established as models of linear logic, concurrency, and quantum computing. We show that it is possible to construct such compact closed categories for conventional sum and product types by defining a dual to sum types, a negative type, and a dual to product types, a fractional type. Inspired by the categorical semantics, we define a sound operational semantics for negative and fractional types in which a negative type represents a computational effect that “reverses execution flow” and a fractional type represents a computational effect that“garbage collects” particular values or throws exceptions. Specifically, we extend a first-order reversible language of type isomorphisms with negative and fractional types, specify an operational semantics for each extension, and prove that each extension forms a compact closed category. We furthermore show that both operational semantics can be merged using the standard combination of backtracking and exceptions resulting in a smooth interoperability of negative and fractional types. We illustrate the expressiveness of this combination by writing a reversible SAT solver that uses back- tracking search along freshly allocated and de-allocated locations. The operational semantics, most of its meta-theoretic properties, and all examples are formalized in a supplementary Agda package. CCS Concepts: • Theory of computation → Type theory; Abstract machines; Operational semantics. Additional Key Words and Phrases: Abstract Machines, Duality of Computation, Higher-Order Reversible Programming, Termination Proofs, Type Isomorphisms ACM Reference Format: Chao-Hong Chen and Amr Sabry.
    [Show full text]
  • Let's Get Functional
    5 LET’S GET FUNCTIONAL I’ve mentioned several times that F# is a functional language, but as you’ve learned from previous chapters you can build rich applications in F# without using any functional techniques. Does that mean that F# isn’t really a functional language? No. F# is a general-purpose, multi paradigm language that allows you to program in the style most suited to your task. It is considered a functional-first lan- guage, meaning that its constructs encourage a functional style. In other words, when developing in F# you should favor functional approaches whenever possible and switch to other styles as appropriate. In this chapter, we’ll see what functional programming really is and how functions in F# differ from those in other languages. Once we’ve estab- lished that foundation, we’ll explore several data types commonly used with functional programming and take a brief side trip into lazy evaluation. The Book of F# © 2014 by Dave Fancher What Is Functional Programming? Functional programming takes a fundamentally different approach toward developing software than object-oriented programming. While object-oriented programming is primarily concerned with managing an ever-changing system state, functional programming emphasizes immutability and the application of deterministic functions. This difference drastically changes the way you build software, because in object-oriented programming you’re mostly concerned with defining classes (or structs), whereas in functional programming your focus is on defining functions with particular emphasis on their input and output. F# is an impure functional language where data is immutable by default, though you can still define mutable data or cause other side effects in your functions.
    [Show full text]
  • Notes on Functional Programming with Haskell
    Notes on Functional Programming with Haskell H. Conrad Cunningham [email protected] Multiparadigm Software Architecture Group Department of Computer and Information Science University of Mississippi 201 Weir Hall University, Mississippi 38677 USA Fall Semester 2014 Copyright c 1994, 1995, 1997, 2003, 2007, 2010, 2014 by H. Conrad Cunningham Permission to copy and use this document for educational or research purposes of a non-commercial nature is hereby granted provided that this copyright notice is retained on all copies. All other rights are reserved by the author. H. Conrad Cunningham, D.Sc. Professor and Chair Department of Computer and Information Science University of Mississippi 201 Weir Hall University, Mississippi 38677 USA [email protected] PREFACE TO 1995 EDITION I wrote this set of lecture notes for use in the course Functional Programming (CSCI 555) that I teach in the Department of Computer and Information Science at the Uni- versity of Mississippi. The course is open to advanced undergraduates and beginning graduate students. The first version of these notes were written as a part of my preparation for the fall semester 1993 offering of the course. This version reflects some restructuring and revision done for the fall 1994 offering of the course|or after completion of the class. For these classes, I used the following resources: Textbook { Richard Bird and Philip Wadler. Introduction to Functional Program- ming, Prentice Hall International, 1988 [2]. These notes more or less cover the material from chapters 1 through 6 plus selected material from chapters 7 through 9. Software { Gofer interpreter version 2.30 (2.28 in 1993) written by Mark P.
    [Show full text]
  • Design Patterns in Ocaml
    Design Patterns in OCaml Antonio Vicente [email protected] Earl Wagner [email protected] Abstract The GOF Design Patterns book is an important piece of any professional programmer's library. These patterns are generally considered to be an indication of good design and development practices. By giving an implementation of these patterns in OCaml we expected to better understand the importance of OCaml's advanced language features and provide other developers with an implementation of these familiar concepts in order to reduce the effort required to learn this language. As in the case of Smalltalk and Scheme+GLOS, OCaml's higher order features allows for simple elegant implementation of some of the patterns while others were much harder due to the OCaml's restrictive type system. 1 Contents 1 Background and Motivation 3 2 Results and Evaluation 3 3 Lessons Learned and Conclusions 4 4 Creational Patterns 5 4.1 Abstract Factory . 5 4.2 Builder . 6 4.3 Factory Method . 6 4.4 Prototype . 7 4.5 Singleton . 8 5 Structural Patterns 8 5.1 Adapter . 8 5.2 Bridge . 8 5.3 Composite . 8 5.4 Decorator . 9 5.5 Facade . 10 5.6 Flyweight . 10 5.7 Proxy . 10 6 Behavior Patterns 11 6.1 Chain of Responsibility . 11 6.2 Command . 12 6.3 Interpreter . 13 6.4 Iterator . 13 6.5 Mediator . 13 6.6 Memento . 13 6.7 Observer . 13 6.8 State . 14 6.9 Strategy . 15 6.10 Template Method . 15 6.11 Visitor . 15 7 References 18 2 1 Background and Motivation Throughout this course we have seen many examples of methodologies and tools that can be used to reduce the burden of working in a software project.
    [Show full text]
  • Scala by Example (2009)
    Scala By Example DRAFT January 13, 2009 Martin Odersky PROGRAMMING METHODS LABORATORY EPFL SWITZERLAND Contents 1 Introduction1 2 A First Example3 3 Programming with Actors and Messages7 4 Expressions and Simple Functions 11 4.1 Expressions And Simple Functions...................... 11 4.2 Parameters.................................... 12 4.3 Conditional Expressions............................ 15 4.4 Example: Square Roots by Newton’s Method................ 15 4.5 Nested Functions................................ 16 4.6 Tail Recursion.................................. 18 5 First-Class Functions 21 5.1 Anonymous Functions............................. 22 5.2 Currying..................................... 23 5.3 Example: Finding Fixed Points of Functions................ 25 5.4 Summary..................................... 28 5.5 Language Elements Seen So Far....................... 28 6 Classes and Objects 31 7 Case Classes and Pattern Matching 43 7.1 Case Classes and Case Objects........................ 46 7.2 Pattern Matching................................ 47 8 Generic Types and Methods 51 8.1 Type Parameter Bounds............................ 53 8.2 Variance Annotations.............................. 56 iv CONTENTS 8.3 Lower Bounds.................................. 58 8.4 Least Types.................................... 58 8.5 Tuples....................................... 60 8.6 Functions.................................... 61 9 Lists 63 9.1 Using Lists.................................... 63 9.2 Definition of class List I: First Order Methods..............
    [Show full text]
  • Control Flow
    Control Flow COMS W4115 Prof. Stephen A. Edwards Spring 2002 Columbia University Department of Computer Science Control Flow “Time is Nature’s way of preventing everything from happening at once.” Scott identifies seven manifestations of this: 1. Sequencing foo(); bar(); 2. Selection if (a) foo(); 3. Iteration while (i<10) foo(i); 4. Procedures foo(10,20); 5. Recursion foo(int i) { foo(i-1); } 6. Concurrency foo() jj bar() 7. Nondeterminism do a -> foo(); [] b -> bar(); Ordering Within Expressions What code does a compiler generate for a = b + c + d; Most likely something like tmp = b + c; a = tmp + d; (Assumes left-to-right evaluation of expressions.) Order of Evaluation Why would you care? Expression evaluation can have side-effects. Floating-point numbers don’t behave like numbers. Side-effects int x = 0; int foo() { x += 5; return x; } int a = foo() + x + foo(); What’s the final value of a? Side-effects int x = 0; int foo() { x += 5; return x; } int a = foo() + x + foo(); GCC sets a=25. Sun’s C compiler gave a=20. C says expression evaluation order is implementation-dependent. Side-effects Java prescribes left-to-right evaluation. class Foo { static int x; static int foo() { x += 5; return x; } public static void main(String args[]) { int a = foo() + x + foo(); System.out.println(a); } } Always prints 20. Number Behavior Basic number axioms: a + x = a if and only if x = 0 Additive identity (a + b) + c = a + (b + c) Associative a(b + c) = ab + ac Distributive Misbehaving Floating-Point Numbers 1e20 + 1e-20 = 1e20 1e-20 1e20 (1 + 9e-7) + 9e-7 6= 1 + (9e-7 + 9e-7) 9e-7 1, so it is discarded, however, 1.8e-6 is large enough 1:00001(1:000001 − 1) 6= 1:00001 · 1:000001 − 1:00001 · 1 1:00001 · 1:000001 = 1:00001100001 requires too much intermediate precision.
    [Show full text]
  • 210 CHAPTER 7. NAMES and BINDING Chapter 8
    210 CHAPTER 7. NAMES AND BINDING Chapter 8 Expressions and Evaluation Overview This chapter introduces the concept of the programming environment and the role of expressions in a program. Programs are executed in an environment which is provided by the operating system or the translator. An editor, linker, file system, and compiler form the environment in which the programmer can enter and run programs. Interac- tive language systems, such as APL, FORTH, Prolog, and Smalltalk among others, are embedded in subsystems which replace the operating system in forming the program- development environment. The top-level control structure for these subsystems is the Read-Evaluate-Write cycle. The order of computation within a program is controlled in one of three basic ways: nesting, sequencing, or signaling other processes through the shared environment or streams which are managed by the operating system. Within a program, an expression is a nest of function calls or operators that returns a value. Binary operators written between their arguments are used in infix syntax. Unary and binary operators written before a single argument or a pair of arguments are used in prefix syntax. In postfix syntax, operators (unary or binary) follow their arguments. Parse trees can be developed from expressions that include infix, prefix and postfix operators. Rules for precedence, associativity, and parenthesization determine which operands belong to which operators. The rules that define order of evaluation for elements of a function call are as follows: • Inside-out: Evaluate every argument before beginning to evaluate the function. 211 212 CHAPTER 8. EXPRESSIONS AND EVALUATION • Outside-in: Start evaluating the function body.
    [Show full text]
  • 61A Lecture 6 Lambda Expressions VS Currying
    Announcements • Homework 2 due Tuesday 9/17 @ 11:59pm • Project 2 due Thursday 9/19 @ 11:59pm • Optional Guerrilla section next Monday for students to master higher-order functions . Organized by Andrew Huang and the readers 61A Lecture 6 . Work in a group on a problem until everyone in the group understands the solution • Midterm 1 on Monday 9/23 from 7pm to 9pm Friday, September 13 . Details and review materials will be posted early next week . There will be a web form for students who cannot attend due to a conflict 2 Lambda Expressions >>> ten = 10 An expression: this one evaluates to a number >>> square = x * x Also an expression: evaluates to a function Lambda Expressions >>> square = lambda x: x * x Important: No "return" keyword! A function with formal parameter x that returns the value of "x * x" >>> square(4) 16 Must be a single expression Lambda expressions are not common in Python, but important in general (Demo) Lambda expressions in Python cannot contain statements at all! 4 Lambda Expressions Versus Def Statements def square(x): square = lambda x: x * x VS return x * x • Both create a function with the same domain, range, and behavior. • Both functions have as their parent the environment in which they were defined. Currying • Both bind that function to the name square. • Only the def statement gives the function an intrinsic name. The Greek letter lambda Example: http://goo.gl/XH54uE 5 Function Currying def make_adder(n): return lambda k: n + k >>> make_adder(2)(3) There's a general 5 relationship between (Demo) >>> add(2, 3) these functions 5 Newton's Method Currying: Transforming a multi-argument function into a single-argument, higher-order function.
    [Show full text]
  • Exam 1 Review: Solutions Capture the Dragons
    CSCI 1101B: Introduction to Computer Science Instructor: Prof. Harmon Exam 1 Review: Solutions Capture the Dragons Boolean Expressions 1. Of the following, which are Boolean expressions? (a)2+3 Not Boolean (b)2>3 Boolean (c) num >= 2 Boolean (d) num1 = num2 Not Boolean 2. If x = 3, and x <= y evaluates to True, what values can y have? y >= 3 3. Simplify each of the following expressions: (a) my_num or True Depends on what the value of my_num is. See rules as in #5. (b) False and "Mary" or True True (c) False and ("Mary" or True) False 4. Is x =< y the same as x <= y? No. Python only recognizes the latter. The former is invalid syntax. 5. If x = 1 and y = 2, explain the following results: (a) >>> x and y # = 2 (b) >>> x or y # = 1 Python uses lazy evaluation. • The expression x and y first evaluates x. If x is equivalent to False (or empty/zero), its value is returned. Otherwise, y is evaluated and the resulting value is returned. • The expression x or y first evaluates x. If x is equivalent to True (or non-empty/nonzero), its value is returned. Otherwise, y is evaluated and the resulting value is returned. 1 CSCI 1101B: Introduction to Computer Science Exam 1 Review: Solutions Conditionals 1. What is indentation, and how is it related to the concept of a code block? Indentation is the placement of text (to the left or right). Python uses indenta- tion to associate code into groups, or blocks. 2. What is the difference between a chained conditional and a nested conditional? Chained => if, elif, else Nested => conditionals exist (are "nested") inside each other 3.
    [Show full text]
  • CSE 341 : Programming Languages
    CSE 341 : Programming Languages Lecture 10 Closure Idioms Zach Tatlock Spring 2014 More idioms • We know the rule for lexical scope and function closures – Now what is it good for A partial but wide-ranging list: • Pass functions with private data to iterators: Done • Combine functions (e.g., composition) • Currying (multi-arg functions and partial application) • Callbacks (e.g., in reactive programming) • Implementing an ADT with a record of functions (optional) 2 Combine functions Canonical example is function composition: fun compose (f,g) = fn x => f (g x) • Creates a closure that “remembers” what f and g are bound to • Type ('b -> 'c) * ('a -> 'b) -> ('a -> 'c) but the REPL prints something equivalent • ML standard library provides this as infix operator o • Example (third version best): fun sqrt_of_abs i = Math.sqrt(Real.fromInt(abs i)) fun sqrt_of_abs i = (Math.sqrt o Real.fromInt o abs) i val sqrt_of_abs = Math.sqrt o Real.fromInt o abs 3 Left-to-right or right-to-left val sqrt_of_abs = Math.sqrt o Real.fromInt o abs As in math, function composition is “right to left” – “take absolute value, convert to real, and take square root” – “square root of the conversion to real of absolute value” “Pipelines” of functions are common in functional programming and many programmers prefer left-to-right – Can define our own infix operator – This one is very popular (and predefined) in F# infix |> fun x |> f = f x fun sqrt_of_abs i = i |> abs |> Real.fromInt |> Math.sqrt 4 Another example • “Backup function” fun backup1 (f,g) = fn x => case
    [Show full text]
  • Top Functional Programming Languages Based on Sentiment Analysis 2021 11
    POWERED BY: TOP FUNCTIONAL PROGRAMMING LANGUAGES BASED ON SENTIMENT ANALYSIS 2021 Functional Programming helps companies build software that is scalable, and less prone to bugs, which means that software is more reliable and future-proof. It gives developers the opportunity to write code that is clean, elegant, and powerful. Functional Programming is used in demanding industries like eCommerce or streaming services in companies such as Zalando, Netflix, or Airbnb. Developers that work with Functional Programming languages are among the highest paid in the business. I personally fell in love with Functional Programming in Scala, and that’s why Scalac was born. I wanted to encourage both companies, and developers to expect more from their applications, and Scala was the perfect answer, especially for Big Data, Blockchain, and FinTech solutions. I’m glad that my marketing and tech team picked this topic, to prepare the report that is focused on sentiment - because that is what really drives people. All of us want to build effective applications that will help businesses succeed - but still... We want to have some fun along the way, and I believe that the Functional Programming paradigm gives developers exactly that - fun, and a chance to clearly express themselves solving complex challenges in an elegant code. LUKASZ KUCZERA, CEO AT SCALAC 01 Table of contents Introduction 03 What Is Functional Programming? 04 Big Data and the WHY behind the idea of functional programming. 04 Functional Programming Languages Ranking 05 Methodology 06 Brand24
    [Show full text]