kids encyclopedia robot

Haskell facts for kids

Kids Encyclopedia Facts
Quick facts for kids
Haskell
Logo of Haskell
Paradigm Purely functional
Designed by Lennart Augustsson, Dave Barton, Brian Boutel, Warren Burton, Joseph Fasel, Kevin Hammond, Ralf Hinze, Paul Hudak, John Hughes, Thomas Johnsson, Mark Jones, Simon Peyton Jones, John Launchbury, Erik Meijer, John Peterson, Alastair Reid, Colin Runciman, Philip Wadler
First appeared 1990; 35 years ago (1990)
Stable release
Haskell 2010 / July 2010; 14 years ago (2010-07)
Preview release
Haskell 2020 announced
Typing discipline Inferred, static, strong
OS Cross-platform
Filename extensions .hs, .lhs
Major implementations
GHC, Hugs, NHC, JHC, Yhc, UHC
Dialects
Gofer
Influenced by
Clean, FP, Gofer, Hope and Hope+, Id, ISWIM, KRC, Lisp,
Miranda, ML and Standard ML, Orwell, SASL, Scheme, SISAL
Influenced
Agda, Bluespec, C++11/Concepts,
C#/LINQ, CAL, Cayenne, Clean, Clojure,
CoffeeScript, Curry, Elm,
Epigram, Escher, F#, Hack, Idris,
Isabelle, Java/Generics, LiveScript,
Mercury, Ωmega, PureScript, Python, Raku,
Rust, Scala, Swift,
Visual Basic 9.0

Haskell is a special kind of programming language. It's used for many different things, like teaching, research, and building real-world applications. Haskell is known for being a "purely functional" language. This means its programs are built using functions, much like in math, where functions always give the same result for the same input.

Haskell also uses "lazy evaluation." This means it only calculates things when they are actually needed, which can make programs more efficient. It also has "type inference," which helps the computer figure out what kind of data you are using without you having to tell it every time. The language is named after a famous logician, Haskell Curry. The main tool for using Haskell is called the Glasgow Haskell Compiler (GHC).

Haskell's design was inspired by another language called Miranda. The latest official version of Haskell was released in 2010. Today, Haskell is used in schools and by companies.

How Haskell Started

After a language called Miranda came out in 1985, people became very interested in "lazy functional languages." By 1987, there were many such languages. Miranda was popular, but it wasn't free to use.

At a big computer science meeting in 1987, everyone agreed to create an open standard for these languages. The goal was to combine the best ideas from existing functional languages. This new language would then be a base for future research.

Early Haskell Versions

A special committee developed Haskell. They tried to use solutions that already worked well.

One important idea they added was "type classes." These help programs handle different types of data safely. For example, they allow you to use the same symbol (like `+`) for adding numbers and combining lists.

In earlier versions, handling user input and output (like showing text on screen) was tricky. In version 1.3, they introduced "monadic I/O." This made it much easier and safer to deal with inputs and outputs in a functional way.

The first version of Haskell, "Haskell 1.0," came out in 1990. The committee kept working on it, releasing new versions like 1.1, 1.2, 1.3, and 1.4.

Haskell 98

In 1997, all this work led to Haskell 98. The idea was to create a stable, simple version of the language. This version would be easy to use for teaching and as a base for new features. It also came with a standard set of tools and functions.

The Haskell 98 language standard was first published in 1999. A newer version came out in 2003. Even though there are official standards, the Glasgow Haskell Compiler (GHC) is often seen as the most up-to-date version of Haskell.

Haskell 2010

In 2006, people started planning the next big update to Haskell 98. This new version, called Haskell 2010, was released in 2010.

Haskell 2010 was an update that added features that were already popular and widely used.

  • Better Module Names: Modules (parts of a program) could now have names like `Data.List` instead of just `List`. This makes it easier to organize code.
  • Connecting to Other Languages: The "foreign function interface" (FFI) was added. This lets Haskell programs work with code written in other languages, like C.
  • Simpler Patterns: Some old ways of writing patterns, like `fact (n+1)`, were removed because they could be confusing.
  • Improved Type Checking: The rules for how the computer checks types were made more flexible, so more programs could work correctly.
  • Syntax Fixes: Some small issues in how the language is written were fixed. For example, "pattern guards" were added, which let you match patterns inside conditions.
  • Language Pragma: A special command called `LANGUAGE` was added. This lets programmers tell the compiler which extra features they want to use.

Future Standards

A new official version was planned for 2020. In 2021, a new set of features called GHC2021 was released with GHC version 9.2.1. While not a formal standard, it combines many stable and popular features from Haskell 2010.

Key Features of Haskell

Haskell has many interesting features that make it unique:

  • Lazy Evaluation: As mentioned, it only calculates things when they are absolutely needed.
  • Lambda Expressions: These are small, unnamed functions that you can use quickly.
  • Pattern Matching: This lets you write code that looks for specific patterns in data. It makes your code very clear and easy to read.
  • List Comprehension: This is a neat way to create lists based on rules, similar to how you might define sets in math.
  • Type Classes: These allow you to define common behaviors for different types of data.
  • Type Polymorphism: This means functions can work with many different types of data, making your code more flexible.

Haskell is a "purely functional language." This means that functions usually don't have "side effects." A side effect is when a function changes something outside of itself, like changing a variable or printing something to the screen. In Haskell, these side effects are handled in a special, controlled way using "monads."

Haskell has a "strong, static type system." This means the computer checks for type errors (like trying to add text to a number) before the program even runs. This helps catch mistakes early.

The main tool for Haskell, the Glasgow Haskell Compiler (GHC), can both run programs directly (as an interpreter) and turn them into code that your computer understands (as a compiler). GHC is known for its advanced type system and for being good at handling "concurrency" (doing many things at once) and "parallelism" (using multiple computer parts to do things at once).

There's a large and active community around Haskell. You can find over 5,400 free, open-source libraries and tools in an online collection called Hackage.

Simple Code Examples

Here's a classic "Hello, World!" program in Haskell. This program simply prints "Hello, World!" to the screen. The last line is the most important part.

module Main (main) where          -- This line is for organizing code, not always needed.

main :: IO ()                     -- This tells the computer what kind of result 'main' will give.
main = putStrLn "Hello, World!"

Now, let's look at how to calculate the factorial of a number in Haskell. The factorial of a number (like 5!) is 5 × 4 × 3 × 2 × 1. Haskell can do this in a few ways:

factorial :: (Integral a) => a -> a -- This line says 'factorial' works with whole numbers.

-- Using recursion (a function calling itself) with 'if-then-else'
factorial n = if n < 2
              then 1
              else n * factorial (n - 1)

-- Using recursion with pattern matching (looking for specific inputs)
factorial 0 = 1
factorial n = n * factorial (n - 1)

-- Using recursion with 'guards' (conditions)
factorial n
   | n < 2     = 1
   | otherwise = n * factorial (n - 1)

-- Using a list and the 'product' function (which multiplies all numbers in a list)
factorial n = product [1..n]

-- Using 'fold' (a way to combine elements in a list)
factorial n = foldl (*) 1 [1..n]

Haskell can handle very large numbers without losing accuracy. So, `factorial 100000` would give you a huge, exact number!

Here's an example of a sorting algorithm, like quick sort, written in Haskell. This code sorts a list of items.

-- This line says 'quickSort' works with lists where items can be ordered.
quickSort :: Ord a => [a] -> [a]

-- Using list comprehensions (a concise way to build lists)
quickSort []     = []                               -- An empty list is already sorted.
quickSort (x:xs) = quickSort [a | a <- xs, a < x]   -- Sort items smaller than 'x'.
                   ++ [x] ++                        -- Put 'x' in the middle.
                   quickSort [a | a <- xs, a >= x]  -- Sort items larger than or equal to 'x'.

-- Using 'filter' (to pick items based on a rule)
quickSort []     = []
quickSort (x:xs) = quickSort (filter (<x) xs)
                   ++ [x] ++
                   quickSort (filter (>=x) xs)

Haskell Tools

Many tools and programs have been made using Haskell. All of them are open source, meaning their code is free for anyone to use and change.

Some important Haskell tools include:

  • The Glasgow Haskell Compiler (GHC): This is the most common Haskell tool. It turns Haskell code into native computer code.
  • Jhc: Another Haskell compiler that focuses on making programs run very fast.
  • The Utrecht Haskell Compiler (UHC): Used for research into new language features.

Older tools that are not actively updated anymore:

  • The Haskell User's Gofer System (Hugs): An older tool that was very popular for learning Haskell.
  • The York Haskell Compiler (Yhc): Could even turn Haskell code into JavaScript so it could run in web browsers.

There are also other versions of Haskell, like Eta and Frege, which are designed to run on the Java virtual machine. Helium is another version that tries to make error messages easier for beginners to understand.

Cool Things Made with Haskell

Haskell is used to create many interesting applications:

  • Agda: A tool that helps prove if computer programs are correct.
  • Cabal: A tool that helps build and package Haskell programs.
  • Darcs: A system for tracking changes in computer code.
  • Git-annex: A tool to manage large data files with Git version control.
  • Pandoc: A tool that can convert documents from one format to another (like from a wiki page to a PDF).
  • Xmonad: A special program that manages windows on a computer screen, written entirely in Haskell.
  • GarganText: A tool for analyzing texts in web browsers, used in research.

Haskell in Companies

Many companies use Haskell for important tasks:

  • Bluespec: Uses Haskell to design computer chips.
  • Cryptol: A tool for creating and checking cryptography (secret code) algorithms.
  • Facebook: Uses Haskell for its anti-spam programs.
  • Cardano: A major blockchain platform that is built using Haskell.
  • GitHub: Uses Haskell for a tool called Semantic, which helps analyze source code.
  • Standard Chartered: A bank that uses a Haskell-based language for financial modeling.
  • seL4: The first formally verified microkernel (a tiny, super-secure part of an operating system) used Haskell for its early design.
  • Target: Uses Haskell for software that helps manage its supply chain.

Haskell for Websites

Haskell can also be used to build websites! Some popular web frameworks (tools that help build websites) written in Haskell include:

  • IHP
  • Servant
  • Snap
  • Yesod

Challenges with Haskell

While Haskell is powerful, it can also be tricky sometimes.

  • Understanding Performance: Because of "lazy evaluation," it can be hard for programmers to guess how fast their code will run or how much memory it will use.
  • Error Messages: For beginners, Haskell's error messages can sometimes be hard to understand. Researchers have created tools like Helium to make these messages clearer.
  • Data Structures: Some traditional ways of handling data, like changing parts of an array, are different in Haskell. This can make it harder to use certain types of data structures.

Haskell's build tool, Cabal, used to have a problem called "Cabal hell." This happened when different parts of a program needed different versions of the same library. Tools like Stackage and Stack were created to fix this. Newer versions of Cabal have also greatly improved this issue.

Languages Like Haskell

Haskell has inspired many other programming languages:

  • Clean: A language very similar to Haskell, but it handles side effects in a different way.
  • Agda: A functional language that helps prove properties of programs.
  • Elm: A functional language used for building web apps.
  • Idris: A general-purpose functional language.
  • PureScript: A language that compiles (turns into) JavaScript.

Other related languages include Curry, which combines ideas from functional and logic programming.

Haskell Events

The Haskell community often meets up for events:

  • International Conference on Functional Programming (ICFP): A big conference about functional programming.
  • Haskell Symposium: A meeting specifically for Haskell research and development.
  • Commercial Users of Functional Programming (CUFP): For companies that use functional programming.
  • ZuriHac: A "hackathon" (a coding event) held every year in Zurich.

Since 2006, there have also been "Hac series" events. These are organized hackathons focused on making Haskell tools and libraries better.

Images for kids

See also

Kids robot.svg In Spanish: Haskell para niños

kids search engine
Haskell Facts for Kids. Kiddle Encyclopedia.