X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fmaster-project%2Fdsd-paper.git;a=blobdiff_plain;f=c%CE%BBash.lhs;h=1dd21ce530709fccda16e1fc74af67c2d0ccf7fc;hp=9c5e5bd182bfac3dc358414af7e15dfaa72b1fee;hb=6835a7a214399baa57eec06aa5698932c4184d42;hpb=31171ef52888a4d111d19b34413596283e1c7b95 diff --git "a/c\316\273ash.lhs" "b/c\316\273ash.lhs" index 9c5e5bd..1dd21ce 100644 --- "a/c\316\273ash.lhs" +++ "b/c\316\273ash.lhs" @@ -525,7 +525,7 @@ functional hardware description language must eventually be converted into a netlist. This research also features a prototype translator called \CLaSH\ (pronounced: clash), which converts the Haskell code to equivalently behaving synthesizable \VHDL\ code, ready to be converted to an actual netlist format -by any (optimizing) \VHDL\ synthesis tool. +by an (optimizing) \VHDL\ synthesis tool. \section{Hardware description in Haskell} @@ -815,7 +815,7 @@ by any (optimizing) \VHDL\ synthesis tool. \end{code} This type is parameterized by \hs{a}, which can contain any type at - all. This means that append can append an element to a vector, + all. This means that \hs{append} can append an element to a vector, regardless of the type of the elements in the list (as long as the type of the value to be added is of the same type as the values in the vector). This kind of polymorphism is extremely useful in hardware designs to make @@ -833,8 +833,8 @@ by any (optimizing) \VHDL\ synthesis tool. type classes, where a class definition provides the general interface of a function, and class instances define the functionality for the specific types. An example of such a type class is the \hs{Num} class, which - contains all of Haskell's numerical operation. A developer can make use of - this ad-hoc polymorphism by adding a constraint to a parametrically + contains all of Haskell's numerical operations. A developer can make use + of this ad-hoc polymorphism by adding a constraint to a parametrically polymorphic type variable. Such a constraint indicates that the type variable can only be instantiated to a type whose members supports the overloaded functions associated with the type class. @@ -861,40 +861,40 @@ by any (optimizing) \VHDL\ synthesis tool. for the type parameters). \CLaSH\ does not support user-defined type classes, but does use some - of the built-in type classes for its built-in function, such asL \hs{Num} - for numerical operations, \hs{Eq} for the equality operators, and + of the built-in type classes for its built-in function, such as: \hs{Num} + for numerical operations, \hs{Eq} for the equality operators, and \hs{Ord} for the comparison/order operators. - \subsection{Higher order} + \subsection{Higher-order functions} Another powerful abstraction mechanism in functional languages, is - the concept of \emph{higher order functions}, or \emph{functions as + the concept of \emph{higher-order functions}, or \emph{functions as a first class value}. This allows a function to be treated as a value and be passed around, even as the argument of another - function. Let's clarify that with an example: + function. The following example should clarify this concept: \begin{code} - notList xs = map not xs + negVector xs = map not xs \end{code} - This defines a function \hs{notList}, with a single list of booleans - \hs{xs} as an argument, which simply negates all of the booleans in - the list. To do this, it uses the function \hs{map}, which takes - \emph{another function} as its first argument and applies that other - function to each element in the list, returning again a list of the - results. - - As you can see, the \hs{map} function is a higher order function, - since it takes another function as an argument. Also note that - \hs{map} is again a polymorphic function: It does not pose any - constraints on the type of elements in the list passed, other than - that it must be the same as the type of the argument the passed - function accepts. The type of elements in the resulting list is of - course equal to the return type of the function passed (which need - not be the same as the type of elements in the input list). Both of - these can be readily seen from the type of \hs{map}: + The code above defines a function \hs{negVector}, which takes a vector of + booleans, and returns a vector where all the values are negated. It + achieves this by calling the \hs{map} function, and passing it + \emph{another function}, boolean negation, and the vector of booleans, + \hs{xs}. The \hs{map} function applies the negation function to all the + elements in the vector. + + The \hs{map} function is called a higher-order function, since it takes + another function as an argument. Also note that \hs{map} is again a + parametric polymorphic function: It does not pose any constraints on the + type of the vector elements, other than that it must be the same type as + the input type of the function passed to \hs{map}. The element type of the + resulting vector is equal to the return type of the function passed, which + need not necessarily be the same as the element type of the input vector. + All of these characteristics can readily be inferred from the type + signature belonging to \hs{map}: \begin{code} - map :: (a -> b) -> [a] -> [b] + map :: (a -> b) -> [a|n] -> [b|n] \end{code} As an example from a common hardware design, let's look at the @@ -915,7 +915,7 @@ by any (optimizing) \VHDL\ synthesis tool. show in the next section about state. \begin{code} - fir ... = foldl1 (+) (zipwith (*) xs hs) + fir {-"$\ldots$"-} = foldl1 (+) (zipwith (*) xs hs) \end{code} Here, the \hs{zipwith} function is very similar to the \hs{map}