Haskell
Logo języka | |
| Pojawienie się |
1990[1] |
|---|---|
| Paradygmat | |
| Typowanie | |
| Implementacje | |
| Aktualna wersja stabilna |
Haskell 9.12.1[2] |
| Twórca |
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 |
| Platforma sprzętowa | |
| Strona internetowa | |
Haskell – czysto funkcyjny język programowania nazwany na cześć amerykańskiego matematyka, Haskella Curry’ego.
Cechy
Jego specyficzne cechy to m.in.:
- leniwe wartościowanie (ang. lazy evaluation),
- wsparcie syntaktyczne monad,
- statyczny polimorfizm,
- klasy typów (ang. typeclasses),
- definiowalne operatory (również możliwość tworzenia nowych),
- strażnicy,
- wbudowana obsługa literate programming.
Rozszerzenia
Pliki Haskella mają rozszerzenie
hslhsgdy zawierają kod w stylu literate programming.
Kompilator
Haskell był początkowo intensywnie rozwijany wokół ośrodka University of Glasgow, popularny kompilator tego języka to Glasgow Haskell Compiler (GHC) kompilujący szybki kod maszynowy porównywalny w szybkości wykonania do kodów z GCC (ok. 1,3 razy wolniejszy niż C)[potrzebny przypis].
Przykłady
-- Komentarz w jednej linijce
{- Komentarze na
wiele linijek
{- można zagnieżdżać -}
-}
-- Przykłady funkcji z dopasowywaniem wzorca
silnia 0 = 1
silnia n = n*silnia(n-1)
silnia n = product [1..n]
fib 0 = 0
fib 1 = 1
fib n = fib(n-1) + fib(n-2)
ack(0,y) = y+1
ack(x,0) = ack(x-1,1)
ack(x,y) = ack(x-1,ack(x,y-1))
-- przykład użycia strażników
sign x | x > 0 = 1
| x == 0 = 0
| x < 0 = -1
myproduct [] = 1
myproduct (n:m) = n * myproduct m
mysum [] = 0
mysum (n:m) = n + mysum m
-- wyrażenia TreeOfMath mają postać: (Sub (Mult (Leaf 5) (Leaf 4)) (Add (Leaf 3) (Leaf 2)))
data TreeOfMath =
Mult TreeOfMath TreeOfMath |
Div TreeOfMath TreeOfMath |
Add TreeOfMath TreeOfMath |
Sub TreeOfMath TreeOfMath |
Leaf Float
compute (Mult x y) = compute x * compute y
compute (Div x y) = compute x / compute y
compute (Add x y) = compute x + compute y
compute (Sub x y) = compute x - compute y
compute (Leaf x) = x
showme (Mult x y) = "(" ++ showme x ++ "*" ++ showme y ++ ")"
showme (Div x y) = "(" ++ showme x ++ "/" ++ showme y ++ ")"
showme (Add x y) = "(" ++ showme x ++ "+" ++ showme y ++ ")"
showme (Sub x y) = "(" ++ showme x ++ "-" ++ showme y ++ ")"
showme (Leaf x) = show x
qsort [] = []
qsort (x:xs) = qsort less ++ x:(qsort more)
where less = [ a | a <- xs, a < x ]
more = [ a | a <- xs, a >= x ]
-- lista liczb pierwszych
primes = map head $ iterate (\(x:xs) -> [ y | y<-xs, y 'mod' x /= 0 ]) [2..]
-- lista liczb Fibonacciego
listFib = 1:1:(zipWith (+) listFib (tail listFib))
Przypisy
- ↑ Paul Hudak, John Hughes, Simon Peyton Jones, Philip Wadler: A History of Haskell: Being Lazy with Class. 2007. ISBN 978-1-59593-766-7.
- ↑ Download — The Glasgow Haskell Compiler [online], www.haskell.org [dostęp 2025-01-24].
Linki zewnętrzne
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.