Haskell is a computer programming language designed by a committee in 1990 to consolidate the best features of the many purely functional programming languagesPlanetmathPlanetmath that were created in the late 1980s. Haskell is thus neither a procedural programming language nor an object-oriented one, although it offers monads such as do to supportMathworldPlanetmathPlanetmath procedural programming and classes with inheritance to support object-oriented programming (there is also a variant of Haskell called O’Haskell which includes more support for object-oriented programming). In general, Haskell programs are most naturally written declaratively.

The standard version of the language is Haskell 98; Haskell 2007 hasn’t been released yet but is expected to be only a minor revision of Haskell 98.

The standard Haskell prelude includes the function gcd, which computes the greatest common divisorMathworldPlanetmathPlanetmath of two integers. The following Haskell code is a reimplementation of the gcd function.

-- gcd.hs -- compute the gcd of two integers
-- View this page in TeX mode for documentation and license.

mygcd :: Int -> Int -> Int
mygcd m n
  | (n < 0)   = mygcd m (abs n)
  | (n == 0)  = m
  | (m < n)   = mygcd n m
  | otherwise = mygcd n (mymod m n)

mydiv :: Int -> Int -> Int
mydiv m n
  | (m < 0)   = negate (mydiv (negate m) n)
  | (n < 0)   = negate (mydiv m (negate n))
  | (m < n)   = 0
  | otherwise = 1 + mydiv (m-n) n

mymod :: Int -> Int -> Int
mymod m n = m - n * (mydiv m n)
Title Haskell
Canonical name Haskell
Date of creation 2013-03-22 16:47:13
Last modified on 2013-03-22 16:47:13
Owner PrimeFan (13766)
Last modified by PrimeFan (13766)
Numerical id 6
Author PrimeFan (13766)
Entry type Definition
Classification msc 68N15