Computer Science

Haskell Programming

Haskell is a functional programming language that emphasizes on immutability and lazy evaluation. It is statically typed and has a strong type system that ensures type safety. Haskell is widely used in academia and industry for research, education, and development of high-performance applications.

Written by Perlego with AI-assistance

6 Key excerpts on "Haskell Programming"

  • Learning F# Functional Data Structures and Algorithms
    Furthermore, various other functional languages were developed in academia, mostly in the areas of mathematical sciences for theorem proving. ML (meta-language) by Robin Milner et al of University of Edinburgh (early 1970s) is a prime example of a programming language used to first implement the Hindley–Milner type inference system. This simply typed polymorphic lambda calculus language was later adapted to build StandardML, Caml, and OCaml, unifying functional, OOP, and imperative programming paradigms. Haskell emerged in 1990 by Simon Jones et al as a purely functional programming language. Haskell supports lazy evaluation, non-strict semantics, and strong static typing. Haskell is named after the logician Haskell Curry. Not surprisingly, Currying is the functional approach to deconstructing a tuple into evaluating a sequence of functions. It allows us to deconstruct a function that takes multiple arguments into an equivalent sequence of sub-functions that are evaluated, one argument at a time. We will explore currying further in the book.
    F#, a product of Don Syme, and Microsoft Research, surfaced in 2005 as a modern multi-paradigm functional programming language. F# originates from ML and has been influenced by OCaml, C#, Python, Haskell, Scala, and Erlang. F# Software Foundation (FSSF) defines the language as follows:
    "F# is a mature, open source, cross-platform, functional-first programming language. It empowers users and organizations to tackle complex computing problems with simple, maintainable and robust code."
    With an open source compiler, library, and toolset, F# is a multi-paradigm language for the .NET platform with support for multiple operating systems via Mono. It supports functional, object oriented, imperative, and explorative programming paradigms. Software developers who specialize in Microsoft platform and tools can easily learn to take advantage of this new language's functional and object-oriented features. This allows them to use their existing skills, find new productivity gains, and leverage new programming design approaches that cannot be easily expressed in objects alone.
    We will be the first to admit that functional programming can be scary for those accustomed to the object oriented and imperative style of coding. While functional programming can lead to some mind-bending coding, the fundamentals are quite straightforward. If you find yourself lost in lambdas
  • Soar with Haskell
    eBook - ePub

    Soar with Haskell

    The ultimate beginners' guide to mastering functional programming from the ground up

    .
    The code shown in this book can be downloaded from its GitHub repository: https://github.com/PacktPublishing/Soar-with-Haskell .

    What is FP?

    Before diving into practical Haskell Programming, we give a brief overview of FP, its history, and its applications. If you are eager to get your hands dirty, you may want to forge ahead to the next section, then return here at a later occasion when you are ready to put Haskell into context.

    Programming with functions

    Functional programming (FP ) is one of the main programming paradigms next to imperative programming and object-oriented programming.

    Declarative programming

    What sets FP apart from the other two is that it is a member of the declarative programming family. Sometimes, the principle of declarative programming is summarized by saying that declarative programs state what should happen, not how it should happen . This means that its programs do not explicitly determine the order in which computation steps are executed; it is up to the language implementation. Haskell particularly stands out among other FP languages because it embraces the declarative programming principle with its lazy evaluation semantics, which Chapter 7 , Lazy Evaluation , explains in detail.

    Function-based programming

    Most members of the declarative programming family use mathematical logic as their basis; programming in the language closely corresponds to writing statements and/or theories in a particular logical framework. Fp distinguishes itself from other declarative paradigms in that it uses mathematical functions as its core concept. Functions are a good formalism for expressing computation as a unit of data processing that turns inputs into outputs. Also, as the concept of functions is widely taught in schools, FP can be more approachable for those without a prior programming background than other programming paradigms. This is one of the reasons it is often taught as the first programming language in academic computer science curricula.
  • Professional Scala
    eBook - ePub
    • Janek Bogucki, Alessandro Lacava, Aliaksandr Bedrytski, Matthew de Detrich, Benjamin Neil(Authors)
    • 2016(Publication Date)
    • Wrox
      (Publisher)
    When a “functional feature” comes to an imperative object-oriented language (see streams in Java 8), you may want to reject it at first. But then, after trying it for some time, you find that you can't develop without it. This chapter provides you with hints about the advantages of functional programming, but it's up to you to decide whether or not functional programming is your cup of tea.
    The previous chapter covered Scala's syntax, and in this chapter we discuss the classical pillars of functional programming language, and how they can be implemented using Scala. Sometimes there will be object-oriented/imperative counterparts, to show you the difference between the two styles of coding.
    So, what are the main characteristics of a functional programming language? It should be transparent, it should have higher order functions and tools to better work with recursion (to use it without being afraid of stack overflows), its functions should be side-effect free, and there should be a possibility of curing and non-strict (also known as lazy) evaluation. This is not a final definition of functional programming, because it varies from language to language (with Haskell being the most known standard), but it covers the basics. You will see how those techniques can increase your productivity, as well as the readability and the safety of your code.
    There are two kinds of people coming to Scala: Java developers who want a more powerful and expressive language that has better tools for working with concurrent systems, and Haskell developers looking for Haskell on a JVM. Due to the limitations of JVM that can't be avoided, the latter group will be disappointed with its capabilities. Those limitations are, however, outside of the scope of this chapter, because they are nonexistent for someone beginning this adventure in functional programming.

    IMMUTABILITY

    Programming languages have a different approach to immutability: some of them embrace it and don't allow any mutable state, and others allow it only through constants that, arguably, are semantically different from a simple immutable value. Scala allows both approaches through val and var
  • Principles of Quantitative Development
    • Manoj Thulasidas(Author)
    • 2012(Publication Date)
    • Wiley
      (Publisher)
    The declarative nature of the language makes it ‘lazy’, meaning that it computes a result only when we ask for it. (At least, that is the principle. In real life, full computational laziness may be difficult to achieve.) Computational laziness makes a functional programming language capable of handling many situations that would be impossible or exceedingly difficult for procedural languages. Users of Mathematica, which is a functional language for symbolic manipulation of mathematical equations, would immediately appreciate the advantages of computational laziness and other functional features such as its declarative nature. In Mathematica, we can carry out an operation like solving an equation for instance. Once that is done, we can add a few more constraints at the bottom of our notebook, scroll up to the command to solve the original equation and re-execute it, fully expecting the later constraints to be respected. They will be, because a statement appearing at a later part in the program listing is not some instruction to be carried out at a later point in a sequence. It is merely a mathematical declaration of truism, no matter where it appears.
    This affinity of functional languages toward mathematics may appeal to quants as well, who are, after all, mathematicians of the applied kind. To see where the appeal stems from, let us consider a simple example of computing the factorial of an integer. In C or C++, we can write a factorial function either using a loop or making use of recursion. In a functional language, on the other hand, we merely restate the mathematical definition, using the syntax of the language we are working with. In mathematics, we define the factorial as
    In Haskell (a well-known functional programming language), we can write:
    bang 1 = 1 bang n = n * bang (n-1)
    and expect to make the call bang 12 to get 12!.
    This factorial example may look artificially simple. However, we can put even more complicated problems from mathematics directly to a functional language. For an example closer to home, let us consider a binomial pricing model, illustrating that the elegance with which Haskell handles a factorial does indeed extend to real-life quantitative finance problems as well.
  • Get Programming with Haskell
    • Will Kurt(Author)
    • 2018(Publication Date)
    • Manning
      (Publisher)

    Unit 3. Programming in types

    Types in Haskell constitute their own way of writing programs. Unit 1 introduced you to the general ideas of functional programming. If this was your first introduction to functional programming, you were likely presented with an entirely new way of thinking about writing code and solving problems. Haskell’s type system is so powerful that it’s best to approach it as a second programming language that works in conjunction with what you learned in unit 1 .
    But what does it mean to think about programming in types? When you look at the type signature of a function—say, a -> b—you can view this signature as a description of a transformation. Suppose you have a type signature CoffeeBeans -> CoffeeGrounds; what function could this possibly describe? Knowing no more than those two types, you could guess that this function is grind. What about CoffeeGrounds -> Water -> Coffee? Clearly, this is the brew function. Types in Haskell allow you to view programs as a series of transformations.
    You can think of transformations as a more abstract level of thinking about functions. When solving problems in Haskell, you can approach them first as a sequence of abstract transformations. For example, say you have a large text document and you need to find all the numbers in that document and then add them all together. How are you going to solve this problem in Haskell? Let’s start with knowing that a document can be represented as a String:
    type Document = String Then you need a function that will break your big String into pieces so you can search for numbers: Document -> [String] Next you need to search for numbers. This will take your list of Strings and a function to check whether a String is a number, and will return your numbers:
  • Alan Turing
    eBook - ePub
    • S. Barry Cooper, J. van Leeuwen(Authors)
    • 2013(Publication Date)
    • Elsevier Science
      (Publisher)
    Turner, 1985 ) was one of the first pure functional programming languages, with lazy evaluation and type inference. Clean (Plasmeijer and van Eekelen, 2002 ) and Haskell (Jones, 2003 ) are modern variants of Miranda. Haskell has become the de facto standard pure functional language, which is widely used in academia.
    Pure functional programming has not yet become mainstream, despite its expressive power and increased safety. To make use of the power, one needs understanding the type systems and the use of the right abstractions. Once mastered, functional programming enables writing applications in a fraction of the usual development and debugging time.

    References

    1. Bove A, Dybjer P, Norell U. A brief overview of Agda – a functional language with dependent types. In: Berghofer S, Nipkow T, Urban C, Wenzel M, eds. Theorem Proving in Higher Order Logics, 22nd International Conference, TPHOLs 2009, Munich, Germany, August 17–20, 2009 . Proceedings, volume 5674 of Lecture Notes in Computer Science, Springer 2009;73–78.
    2. Church A. An unsolvable problem of elementary number theory. Am J Math . 1936;58(2):345–363.
    3. Coq Development Team, 2010. The Coq Proof Assistant Reference Manual – Version V8.3. URL: < http://coq.inria.fr > .
    4. Hammond K, Michaelson G. Research Directions in Parallel Functional Programming . Springer 1999.
    5. Jones SP. Haskell 98 Language and Libraries: The Revised Report . 2003; Cambridge University Press.
    6. Leroy X. A formally verified compiler back-end. J Autom Reason . 2009;43(4):363–446.
    7. Marlow S, Jones SLP, Singh S. Runtime support for multicore Haskell. In: Hutton G, Tolmach AP, eds. Proceeding of the 14th ACM SIGPLAN International Conference on Functional Programming, ICFP 2009 . Edinburgh, Scotland, UK: ACM; 2009;65–78. August 31–September 2.
    8. McCarthy J, Abrahams PW, Edwards DJ, Hart TP, Levin MI. LISP 1.5 Programmer’s Manual
Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.