Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Glasgow Haskell Compiler
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Language== GHC complies with the language standards, both ''Haskell 98''<ref name="h98"> {{cite web | title = Haskell 98 Language and Libraries: The Revised Report | url = https://www.haskell.org/onlinereport/ | website = Haskell.org | access-date = 28 January 2007 }} </ref> and ''Haskell 2010''.<ref name="h2010"> {{cite web | title = Haskell 2010 Language Report | url = https://www.haskell.org/onlinereport/haskell2010/ | website = Haskell.org | access-date = 30 August 2012 }} </ref> It also supports many optional extensions to the Haskell standard: for example, the [[software transactional memory]] (STM) library, which allows for [[Composable Memory Transactions]]. ===Extensions to Haskell=== Many extensions to Haskell have been proposed. These provide features not described in the language specification, or they redefine existing constructs. As such, each extension may not be supported by all Haskell implementations. There is an ongoing effort<ref>{{cite web |title = Welcome to Haskell' (Haskell Prime) |url = https://prime.haskell.org |website = Haskell.org |access-date = 26 May 2016 |archive-date = 20 February 2016 |archive-url = https://web.archive.org/web/20160220103915/https://prime.haskell.org/ |url-status = dead }}</ref> to describe extensions and select those which will be included in future versions of the language specification. The extensions<ref>{{cite web | title = GHC Language Features | url = https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/lang.html | website = Haskell.org | access-date = 25 May 2016 | archive-date = 29 June 2016 | archive-url = https://web.archive.org/web/20160629143456/https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/lang.html | url-status = dead }}</ref> supported by the Glasgow Haskell Compiler include: * Unboxed types and operations. These represent the primitive datatypes of the underlying hardware, without the indirection of a pointer to the [[dynamic allocation|heap]] or the possibility of deferred evaluation. Numerically intensive code can be significantly faster when coded using these types. * The ability to specify [[strict evaluation]] for a value, pattern binding, or datatype field. * More convenient syntax for working with modules, patterns, [[list comprehension]]s, operators, records, and tuples. * [[Syntactic sugar]] for computing with [[arrow (functional programming)|arrows]] and recursively-defined [[Monad (functional programming)|monadic]] values. Both of these concepts extend the monadic {{mono|do}}-notation provided in standard Haskell. * A significantly more powerful system of types and typeclasses, described below. * [[Template Haskell]], a system for compile-time [[metaprogramming]]. Expressions can be written to produce Haskell code in the form of an [[abstract syntax tree]]. These expressions are typechecked and evaluated at compile time; the generated code is then included as if it were part of the original code. Together with the ability to [[Reflective programming|reflect]] on definitions, this provides a powerful tool for further extensions to the language. * Quasi-quotation, which allows the user to define new concrete syntax for expressions and patterns. Quasi-quotation is useful when a metaprogram written in Haskell manipulates code written in a language other than Haskell. * [[Generic programming|Generic]] typeclasses, which specify functions solely in terms of the algebraic structure of the types they operate on. * Parallel evaluation of expressions using multiple CPU cores. This does ''not'' require explicitly spawning threads. The distribution of work happens implicitly, based on annotations provided in the program. * Compiler [[Directive (programming)|pragmas]] for directing optimizations such as [[inline expansion]] and specializing functions for particular types. * Customizable rewrite rules are rules describing how to replace one expression with an equivalent, but more efficiently evaluated expression. These are used within core [[data structure]] libraries to improve performance throughout application-level code.<ref> {{cite conference | last1 = Coutts | first1 = D. | last2 = Leshchinskiy | first2 = R. | last3 = Stewart | first3 = D. | date = April 2007 | title = Stream Fusion: From Lists to Streams to Nothing at All | book-title = Procedures of the ACM SIGPLAN International Conference on Functional Programming (ICFP) | url-status = dead | url = http://www.cse.unsw.edu.au/~dons/papers/CLS07.html | archive-url = https://web.archive.org/web/20070923094030/http://www.cse.unsw.edu.au/~dons/papers/CLS07.html | archive-date = 23 September 2007 }} </ref> * Record dot syntax. Provides [[syntactic sugar]] for accessing the fields of a (potentially nested) record which is similar to the syntax of many other programming languages.<ref> {{cite web | last1 = Mitchell | first1 = Neil | last2 = Fletcher | first2 = Shayne | date = 3 May 2020 | title = Record Dot Syntax | url = https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0282-record-dot-syntax.rst | work = ghc-proposals | publisher = [[GitHub]] | access-date = 30 June 2020 }} </ref> ===Type system extensions=== An expressive static type system is one of the major defining features of Haskell. Accordingly, much of the work in extending the language has been directed towards [[data type]]s and [[type class]]es. The Glasgow Haskell Compiler supports an extended type system based on the theoretical System F<sub>C</sub>.<ref name="Sulzmann2007"/> Major extensions to the type system include: * [[Parametric polymorphism#Higher-ranked polymorphism|Arbitrary-rank]] and [[Parametric polymorphism#Impredicative polymorphism|impredicative]] [[Polymorphism (computer science)|polymorphism]]. Essentially, a polymorphic function or datatype constructor may require that one of its arguments is also polymorphic. * [[Generalized algebraic data type]]s. Each constructor of a polymorphic datatype can encode information into the resulting type. A function which pattern-matches on this type can use the per-constructor type information to perform more specific operations on data. * [[Existential type]]s. These can be used to "bundle" some data together with operations on that data, in such a way that the operations can be used without exposing the specific type of the underlying data. Such a value is very similar to an [[object (computer science)|object]] as found in [[object-oriented programming]] languages. * Data types that do not actually contain any values. These can be useful to represent data in type-level [[metaprogramming]]. * [[Type families]]: user-defined functions from types to types. Whereas parametric polymorphism provides the same structure for every type instantiation, type families provide ''ad hoc'' polymorphism with implementations that can differ between instantiations. Use cases include content-aware optimizing containers and type-level metaprogramming. * Implicit function parameters that have dynamic [[scope (programming)|scope]]. These are represented in types in much the same way as type class constraints. * [[Linear types]] (GHC 9.0) Extensions relating to [[type class]]es include: * A type class may be parametrized on more than one type. Thus a type class can describe not only a set of types, but an ''n''-ary [[finitary relation|relation]] on types. * [[Functional dependencies]], which constrain parts of that relation to be a mathematical [[function (mathematics)|function]] on types. That is, the constraint specifies that some type class parameter is completely determined once some other set of parameters is fixed. This guides the process of [[type inference]] in situations where otherwise there would be ambiguity. * Significantly relaxed rules regarding the allowable shape of type class instances. When these are enabled in full, the type class system becomes a [[Turing-complete]] language for [[logic programming]] at compile time. * Type families, as described above, may also be associated with a type class. * The automatic generation of certain type class instances is extended in several ways. New type classes for [[generic programming]] and common recursion patterns are supported. Also, when a new type is declared as [[isomorphic]] to an existing type, any type class instance declared for the underlying type may be lifted to the new type "for free".
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)