1 \chapter[chap:context]{Context}
2 An obvious question that arises when starting any research is \quote{Has
3 this not been done before?} Using a functional language for describing hardware
4 is not a new idea at all. In fact, there has been research into functional
5 hardware description even before the conventional hardware description
6 languages were created. \todo{Reference about early FHDLs} However,
7 functional languages were not nearly as advanced as they are now, and
8 functional hardware description never really got off.
11 Recently, there have been some renewed efforts, especially using the Haskell
12 functional language. Examples are Lava, ForSyde, ..., which are all a form of an
13 embedded domain specific language. Each of these have a slightly different
14 approach, but all of these do some trickery inside the Haskell language
15 itself, meaning you write a program that generates a hardware circuit,
16 instead of describing the circuit directly (either by running the haskell
17 code after compilation, or using Template Haskell to inspect parts of the
18 code you have written). This allows the full power of Haskell for generating
19 a circuit. However it also creates severe limitations in the use of the
20 language (you can't use case statements in Lava, since they would be
21 executed only once during circuit generation) and extra notational overhead.
23 We will now have a look at the existing hardware description languages,
24 both conventional and functional to see the fields in which Cλash is
27 \section{Conventional hardware description languages}
28 Considering that we already have some hardware description languages like
29 \small{VHDL} and Verilog, why would we need anything else? By introducing
30 the functional style to hardware description, we hope to obtain a hardware
31 description language that is:
33 \item More consise. Functional programs are known for their conciseness
34 and ability to abstract away common patterns. This is largely enabled
35 by features like an advanced type system with polymorphism and higher
37 \todo{Does this apply to FHDLs equally?}
38 \item Type-safer. Functional programs typically have a highly expressive
39 type system, which makes it harder to write incorrect code.
40 \item Easy to process. Functional languages have nice properties like
41 purity \refdef{purity} and single binding behaviour, which make it easy
42 to apply program transformations and optimizations and could potentially
43 simplify program verification.
48 \startframedtext[width=8.5cm,background=box,frame=no]
49 \startalignment[center]
50 {\tfa Embedded domain-specific languages (\small{EDSL})}
54 \startcitedquotation[hudak96]
55 A domain-specific language (\small{DSL}) is a program-
56 ming language or executable specification language
57 that offers, through appropriate notations and ab-
58 stractions, expressive power focused on, and usu-
59 ally restricted to, a particular problem domain.
62 \todo{ref: http://portal.acm.org/citation.cfm?id=352035\&dl=}
64 An embedded \small{DSL} is a \small{DSL} that is embedded in
65 another language. Haskell is commonly used to embed \small{DSL}s
66 in, which typically means a number of Haskell functions and types
67 are made available that can be called to construct a large value
68 of some domain-specific datatype (\eg, a circuit datatype). This
69 generated datatype can then be processed further by the
70 \small{EDSL} \quote{compiler} (which runs in the same environment
71 as the \small{EDSL} itself. The embedded language is then a, mostly
72 applicative, subset of Haskell where the library functions are the
73 primitives. Sometimes advanced haskell features such as
74 polymorphism, higher order values or type classes can be used in
75 the embedded language.
79 \section[sec:context:fhdls]{Existing functional hardware description languages}
80 As noted above, we're not the first to walk this path. However, current
81 embedded functional hardware description languages (in particular those
82 using Haskell) are limited by:\todo{Separate TH and EDSL approaches
85 \item Not all of Haskell's constructs can be captured by embedded domain
86 specific languages. For example, an if or case expression is typically
87 executed only once and only its result is reflected in the embedded
88 description, not the if or case expression itself. Also, sharing of
89 variables (\eg, using the same variable twice while only calculating it
90 once) and cycles in circuits are non-trivial to properly and safely
91 translate (though there is some work to fix this, but that has not been
92 possible in a completely reliable way yet. \todo{ref
93 http://www.ittc.ku.edu/~andygill/paper.php?label=DSLExtract09}
94 \item Some things are verbose to express. Especially ForSyDe suffers
95 from a lot of notational overhead due to the Template Haskell approach
96 used. Since conditional statements are not supported, a lot of Haskell's
97 syntax sugar (if expressions, pattern matching, guards) cannot be used
98 either, leading to more verbose notation as well.
99 \item Polymorphism and higher order values are not supported within the
100 embedded language. The use of Haskell as a host language allows the use
101 of polymorphism and higher order functions at circuit generation time
102 (even for free, without any additional cost on the \small{EDSL}
103 programmers), but the described circuits do not have any polymorphism
104 or higher order functions, which can be limiting. \todo{How true or
105 appropriate is this point?}
106 \todo[left]{Function structure gets lost (in Lava)}
109 \todo[text]{Complete translation in TH is complex: Works with Haskell AST
112 % vim: set sw=2 sts=2 expandtab: