ComputerScientist
174 subscribers
14 photos
3 files
206 links
▜ The Inventor

Stuff that inspire you to create.

See also: ▙ @LitMind
Download Telegram
#language #Haskell
Haskell

First appeared: 1990

Features:
• Purely #functional
• Statically and strongly typed (#Static_typing, #Strong_typing)
#Type_inferring
• Lazy (#Lazy_evaluation)
#pattern_matching
#list_comprehension
• Type classes and type polymorphism (#type_class)
• Concurrent (#concurrency)
• Monads

Monads
Monads are a general framework that can model different kinds of computation, including error handling, nondeterminism, parsing and software transactional memory. Monads are defined as ordinary datatypes, but Haskell provides some syntactic sugar for their use.

Glasgow Haskell Compiler
GHC or Glasgow Haskell Compiler is the most commonly-used Haskell compiler and the main implementation of Haskell. It is open source and provides a cross-platform environment for writing and testing. It supports numerous extensions, libraries, and optimisations that streamline the process of generating and executing code. GHC itself is written in Haskell (#Bootstrapping); but the runtime system which is essential to run programs is written in C and C--.

Front end: (lexer, parser and typechecker)
Preserves as much information about the source as possible until after type inference is complete, to provide clear error messages to users. After type checking, the code is desugared (#syntactic_sugar) into a typed, intermediate language known as "Core".

Simplifier or "middle end":
- is where most of the optimizations are performed as a series of source-to-source transformations in Core code.

Back end:
Transforms Core code into an internal representation of C--. The C-- code can then take one of three routes: it is either printed as C code for compilation with GCC, converted directly into native machine code, or converted to LLVM virtual machine code for compilation with LLVM. In all three cases, the resultant native code is finally linked against the GHC runtime system to produce an executable.

C--
C-- is a #C like programming language, designed to be generated by compilers for very high-level languages rather than written by human programmers. Unlike many other intermediate languages, its representation is plain #ASCII text, not bytecode or another binary format.

C-- is a "portable #assembly language", designed to ease the task of implementing a compiler which produces high quality #machine_code. This is done by having the compiler generate C-- code, delegating the harder work of low-level code generation and optimisation to a C-- compiler.

The C-- type system is deliberately designed to reflect constraints imposed by hardware rather than conventions imposed by higher-level languages. In C-- a value stored in a register or memory may have only one type: bit vector. However, bit vector is a polymorphic type and may come in several widths, e.g., bits8, bits32, or bits64. In addition to the bit-vector type C-- also provides a Boolean type bool, which can be computed by expressions and used for control flow but cannot be stored in a register or in memory. As in an assembly language, any higher type discipline, such as distinctions between signed, unsigned, float, and pointer, is imposed by the C-- operators or other syntactic constructs in the language.
#characters #ASCII
Whitespace
9 character tabulation
10 line feed*
11 line tabulation
12 form feed
13 carriage return*
32 space

*line endings

MS Windows files use CR+LF as line ending.
String
- is a composite, usually built-in, data type implemented as an array, or some other sequential data structure, of bytes.

Fixed-length versus variable-length strings
Although formal strings can have an arbitrary but finite length, the length of strings in real languages is often constrained to an artificial maximum. In general, there are two types of string datatypes: fixed-length strings, which have a fixed maximum length to be determined at compile time and which use the same amount of memory whether this maximum is needed or not, and variable-length strings, whose length is not arbitrarily fixed and which can use varying amounts of memory depending on the actual requirements at run time. Most strings in modern programming languages are variable-length strings.

Terminated versus length-field strings
The string length is either explicitly stored as a separate integer or implicitly through a termination character, usually the null character (NUL), which has all bits zero, a convention used and perpetuated by #C. In terminated strings, the terminating code is not an allowable character in any string; whereas strings with a length field do not have this limitation.

Length versus size
Representations of strings depend on character encoding. Older implementations use #ASCII, and modern implementations use Unicode. With certain encodings, a single logical character may take up more than one entry in the array. In these cases, the logical length of the string (number of characters) differs from the physical length of the array (number of bytes in use).