Haskell

Iz MaFiRaWiki

Haskell je len, popolnoma funkcijski programski jezik s polimorfičnimi tipi, ki omogoča izjemno elegantno implementacijo matematičnih struktur, predvsem neskončnih.

Primeri programov

Zaporedji Fibonaccijevih števil in praštevil lahko opišemo z rekurzivnima definicijama

module Zaporedji where

fib = 1 : 1 : [ a + b | (a, b) <- zip fib (tail fib) ]

pra = reseto [2..]
reseto (p : xs) = p : reseto [ x | x <- xs, x `mod` p > 0]

V interaktivni zanki lahko poprej definirani zaporedji tudi členoma seštejemo.

__   __ __  __  ____   ___      _________________________________________
||   || ||  || ||  || ||__      Hugs 98: Based on the Haskell 98 standard
||___|| ||__|| ||__||  __||     Copyright (c) 1994-2001
||---||         ___||           World Wide Web: http://haskell.org/hugs
||   ||                         Report bugs to: hugs-bugs@haskell.org
||   || Version: February 2001  _________________________________________

Haskell 98 mode: Restart with command line option -98 to enable extensions

Reading file "/sw/share/hugs/lib/Prelude.hs":
                   
Hugs session for:
/sw/share/hugs/lib/Prelude.hs
Type :? for help
Prelude> :load "Zaporedji.hs"
Reading file "Zaporedji.hs":
                   
Zaporedji.hs
Zaporedji> zipWith (+) fib pra
[3,4,7,10,16,21,30,40,57,84,120,181,274,420,657,1040,1656,2645,4248,6836,11019,17790,28740,46457,75122,121494,
196521,317918,514338,832153,1346396,2178440,3524715,5703026,9227614,14930503,24157974,39088332,63246153,
102334328,165580320,267914477,433494628,701408926,1134903367,1836312102,2971215284,4807527199,
7778742276,12586269254,20365011307,32951280338,53316291414,86267571523,139583862702,225851433980,
365435296431,591286730150,956722026318,1548008756201,2504730782244,4052739538174,6557470320149,
10610209858034,17167680177878,27777890035605,44945570213184,72723460248478,117669030461341,
190392490709484,308061521170482,498454011879623,806515533049760,1304969544929030,2111485077978429,
3416454622907090,5527939700885146,8944394323791861,14472334024676622,23416728348468094,...

Izpis zaporedja je omejen zgolj s količino pomnilnika.

Glej tudi

Osebna orodja