Computing and Information Technology Interactive Digital Educational Library


Planet Math Computer Science  >
Planet Math Computer Science Collection >

Please use this identifier to cite or link to this item:

Title: Haskell
Issue Date: 9-Mar-2007
Publisher: PlanetMath
Abstract: ... Haskell is a computer programming language designed by a committee in 1990 to consolidate the best features of the many purely functional programming languages 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 support 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 divisor of two integers. The following Haskell code is a reimplementation of the ... gcd function. % gcd.hs -- compute the gcd of two integers % Copyright (C) 2007 by Michael Slone. % % This program is free software. You may read, study, % copy, modify, and distribute modified copies of this % program according to the terms of the GNU General % Public License, version 2. % % The first line, % mygcd:: Int -> Int -> Int, % is a type declaration. It indicates that mygcd expects to % receive two integers and expects to return a single integer. % The function is defined using equations. If no equation % applies, an error occurs. For example, trying ... % yields the following error message in ghci. % % *Main> mygcd 5 5.2 % % interactive:1:8: % No instance for (Fractional Int) % arising from the literal `5.2' at interactive:1:8-10 % Probable fix: add an instance declaration for (Fractional Int) % In the second argument of `mygcd', namely `5.2' % In the definition of `it': it = mygcd 5 5.2 % % Whitespace can matter in Haskell, so if you wish to use this % code, please copy directly from the TeX source of this page % instead of the HTML version. ... -- gcd.hs -- compute the gcd of two integers -- View this page in TeX mode for documentation and license.
Appears in Collections:Planet Math Computer Science Collection

Files in This Item:

There are no files associated with this item.

All items in DSpace are protected by copyright, with all rights reserved.


Valid XHTML 1.0! DSpace Software Copyright © 2002-2006 MIT and Hewlett-Packard - Feedback