Skip to content

Commit 3a59296

Browse files
committed
Libraries Doc: Fix section on numeric and string type operators
Fix typos in the index entries, standardize headings, correctly identify type functions from pseudo-functions, and separately document the SizeOf type function from the sizeOf pseudo-function.
1 parent 2bc0176 commit 3a59296

File tree

1 file changed

+97
-52
lines changed

1 file changed

+97
-52
lines changed

doc/libraries_ref_guide/LibDoc/Prelude.tex

+97-52
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ \subsubsection{SaturatingArith}
14551455
14561456
\end{verbatim}
14571457

1458-
\subsubsection{Alias and NumAlias}
1458+
\subsubsection{Alias, NumAlias, and StrAlias}
14591459
\label{sec-alias}
14601460
\index{Alias}
14611461
\index{NumAlias}
@@ -4169,15 +4169,14 @@ \subsubsection{Rules}
41694169
%================================================================
41704170
\subsection{Operations on Numeric and String Types}
41714171

4172-
\subsubsection{Size Relationship/Provisos}
4172+
\subsubsection{Size Relationship Provisos}
41734173

4174-
\index{provisos}
4175-
\index{Add@\te{Add} (type provisos)}
4176-
\index{Max@\te{Max} (type provisos)}
4177-
\index{Min@\te{Min} (type provisos)}
4178-
\index{Log@\te{Log} (type provisos)}
4179-
\index{Mul@\te{Mul} (type provisos)}
4180-
\index{Div@\te{Div} (type provisos)}
4174+
\index{Add@\te{Add} (type class)}
4175+
\index{Mul@\te{Mul} (type class)}
4176+
\index{Div@\te{Div} (type class)}
4177+
\index{Max@\te{Max} (type class)}
4178+
\index{Min@\te{Min} (type class)}
4179+
\index{Log@\te{Log} (type class)}
41814180

41824181

41834182

@@ -4223,22 +4222,22 @@ \subsubsection{Size Relationship/Provisos}
42234222

42244223
\subsubsection{Size Relationship Type Functions}
42254224

4226-
\index{TAdd@\te{TAdd} (type functions)}
4227-
\index{TSub@\te{TSub} (type functions)}
4228-
\index{TLog@\te{TLog} (type functions)}
4229-
\index{TExp@\te{TExp} (type functions)}
4230-
\index{TMul@\te{TMul} (type functions)}
4231-
\index{TDiv@\te{TDiv} (type functions)}
4232-
\index{TMax@\te{TMax} (type functions)}
4233-
\index{TMin@\te{TMin} (type functions)}
4225+
\index{TAdd@\te{TAdd} (type function)}
4226+
\index{TSub@\te{TSub} (type function)}
4227+
\index{TMul@\te{TMul} (type function)}
4228+
\index{TDiv@\te{TDiv} (type function)}
4229+
\index{TLog@\te{TLog} (type function)}
4230+
\index{TExp@\te{TExp} (type function)}
4231+
\index{TMax@\te{TMax} (type function)}
4232+
\index{TMin@\te{TMin} (type function)}
42344233
\index[function]{Prelude!TAdd}
42354234
\index[function]{Prelude!TSub}
4235+
\index[function]{Prelude!TMul}
4236+
\index[function]{Prelude!TDiv}
42364237
\index[function]{Prelude!TLog}
42374238
\index[function]{Prelude!TExp}
4238-
\index[function]{Prelude!TMul}
42394239
\index[function]{Prelude!TMax}
42404240
\index[function]{Prelude!TMin}
4241-
\index[function]{Prelude!TDiv}
42424241

42434242
These type functions are used when ``defining'' size relationships between data
42444243
types, where the defined value need not (or cannot) be named in a proviso. They may be used in datatype definition statements when the
@@ -4247,7 +4246,7 @@ \subsubsection{Size Relationship Type Functions}
42474246
\begin{center}
42484247
\begin{tabular}{|p {1 in}|p{1.5 in}| p{2.0 in}|}
42494248
\hline
4250-
Type Function& Size Relationship& Description\\
4249+
Type Function& Application& Description\\
42514250
\hline
42524251
\hline
42534252
\te{TAdd}&\verb'TAdd#(n1,n2)'&Calculate $n1 + n2$\\
@@ -4289,19 +4288,50 @@ \subsubsection{Size Relationship Type Functions}
42894288

42904289

42914290
% ================================================================
4292-
\subsubsection{valueOf and SizeOf pseudo-functions}
4291+
\subsubsection{SizeOf Type Function}
4292+
\index{SizeOf@\te{SizeOf} (type function)}
4293+
\index[function]{Prelude!SizeOf}
4294+
4295+
The \te{Bits} type class expresses the relationship between a type
4296+
and the size of its bit-vector representation.
4297+
The \te{SizeOf} type function is used to access that size, where
4298+
the value need not (or cannot) be named in a \te{Bits} proviso.
4299+
It may be used in datatype definition statements to compute a size
4300+
from another parameter or from an explicit type.
4301+
4302+
\begin{center}
4303+
\begin{tabular}{|p {1 in}|p{1.5 in}| p{2.0 in}|}
4304+
\hline
4305+
Type Function& Application& Description\\
4306+
\hline
4307+
\hline
4308+
\te{SizeOf}&\verb'SizeOf#(t)'&The \te{Bits} size of \te{t} as a numeric type\\
4309+
\hline
4310+
\end{tabular}
4311+
\end{center}
4312+
4313+
{\bf Examples}
4314+
\begin{libverbatim}
4315+
any_type x = ... ;
4316+
Bit#(SizeOf#(any_type)) b = pack(x);
4317+
\end{libverbatim}
4318+
4319+
4320+
\subsubsection{valueOf, sizeOf, and stringOf Pseudo-functions}
42934321
\index{valueof@\texttt{valueof} (pseudo-function of size types)}
42944322
\index{valueOf@\texttt{valueOf} (pseudo-function of size types)}
4295-
\index{SizeOf@\texttt{SizeOf} (pseudo-function on types)}
4323+
\index{sizeOf@\texttt{sizeOf} (pseudo-function of value types)}
4324+
\index{stringOf@\texttt{stringOf} (pseudo-function of string types)}
42964325
\index[function]{Prelude!valueOf}
4297-
\index[function]{Prelude!SizeOf}
4326+
\index[function]{Prelude!sizeOf}
4327+
\index[function]{Prelude!stringOf}
4328+
4329+
Prelude provides three pseudo-functions to convert from types to values.
4330+
Unlike ordinary functions from values to values, the arguments of these
4331+
pseudo-functions are parsed as types.
42984332

4299-
Prelude provides these pseudo-functions to convert between
4300-
types and numeric values. The pseudo-function \te{valueof} (or
4301-
\te{valueOf}) is used to convert a numeric type into the corresponding
4302-
Integer value.
4303-
The pseudo-function \te{SizeOf} is used to convert a type {t} into
4304-
the numeric type representing its bit size.
4333+
The pseudo-function \te{valueOf} (or \te{valueof}) is used to convert
4334+
a numeric type into the corresponding Integer value.
43054335

43064336
\begin{center}
43074337
\begin{tabular}{|p{1 in}|p{4.6 in}|}
@@ -4311,7 +4341,7 @@ \subsubsection{valueOf and SizeOf pseudo-functions}
43114341
\te{valueOf}& \\
43124342
\cline{2-2}
43134343
&\begin{libverbatim}
4314-
function Integer valueOf (t) ;
4344+
function Integer valueOf (numeric type t) ;
43154345
\end{libverbatim}
43164346
\\
43174347
\hline
@@ -4321,24 +4351,28 @@ \subsubsection{valueOf and SizeOf pseudo-functions}
43214351
{\bf Examples}
43224352
\begin{libverbatim}
43234353
module mkFoo (Foo#(n));
4324-
UInt#(n) x;
43254354
Integer y = valueOf(n);
43264355
endmodule
43274356
\end{libverbatim}
43284357

4329-
4358+
The pseudo-function \te{sizeOf} is used to convert a type \te{t} into
4359+
the numeric type representing its bit size. It is equivalent to
4360+
applying \te{valueOf} to the \te{SizeOf} type constructor, but
4361+
is provided for convenience. This pseudo-function carries a
4362+
\te{Bits} proviso and can therefore only be used for types that
4363+
are members of the \te{Bits} type class.
43304364

43314365
\begin{center}
43324366
\begin{tabular}{|p{1 in}|p{4.6 in}|}
43334367
\hline
43344368
& \\
4335-
\te{SizeOf} & Converts a type into a numeric type representing its
4369+
\te{sizeOf} & Converts a type into a numeric type representing its
43364370
bit size.\\
43374371
& \\
43384372
\cline{2-2}
43394373
&\begin{libverbatim}
4340-
function t SizeOf#(any_type)
4341-
provisos (Bits#(any_type, sa)) ;
4374+
function Integer sizeOf (type t)
4375+
provisos (Bits#(t, tsz)) ;
43424376
\end{libverbatim}
43434377
\\
43444378
\hline
@@ -4347,23 +4381,16 @@ \subsubsection{valueOf and SizeOf pseudo-functions}
43474381

43484382
{\bf Examples}
43494383
\begin{libverbatim}
4350-
any_type x = structIn;
4351-
Bit#(SizeOf#(any_type)) = pack(structIn);
4384+
module mkFoo (Ifc#(t)) provisos (Bits#(t,szt));
4385+
Integer num_bits_of_t = sizeOf(t);
4386+
// The above is equivalent to each of the following
4387+
//Integer num_bits_of_t = valueOf(SizeOf#(t));
4388+
//Integer num_bits_of_t = valueOf(szt);
4389+
endmodule
43524390
\end{libverbatim}
43534391

4354-
% ================================================================
4355-
\subsubsection{String type pseudo-functions}
4356-
\index{stringOf@\texttt{valueOf} (pseudo-function of types)}
4357-
\index{TStrCat@\texttt{TStrCat} (pseudo-function on types)}
4358-
\index{TNumToStr@\texttt{TNumToStr} (pseudo-function on types)}
4359-
\index[function]{Prelude!stringOf}
4360-
\index[function]{Prelude!TStrCat}
4361-
\index[function]{Prelude!TNumToStr}
4362-
4363-
Prelude also provides similar pseudo-functions for string types.
4364-
The pseudo-function \te{stringOf} is used to convert a string type into a \te{String} value.
4365-
The type-level pseudo-function \te{TStrCat} is used to concatenate two string types,
4366-
and \te{TNumToStr} is used to convert a numeric type into a string type.
4392+
The pseudo-function \te{stringOf} is used to convert a string type
4393+
into a \te{String} value.
43674394

43684395
\begin{center}
43694396
\begin{tabular}{|p{1 in}|p{4.6 in}|}
@@ -4372,17 +4399,35 @@ \subsubsection{String type pseudo-functions}
43724399
\te{stringOf}&Converts a string type into its String value.\\
43734400
\cline{2-2}
43744401
&\begin{libverbatim}
4375-
function String stringOf (t) ;
4402+
function String stringOf (string type t) ;
43764403
\end{libverbatim}
43774404
\\
43784405
\hline
43794406
\end{tabular}
43804407
\end{center}
43814408

4409+
{\bf Examples}
4410+
\begin{libverbatim}
4411+
module mkFoo (IfcWithStr#(s_type));
4412+
String s_value = stringOf(s_type);
4413+
endmodule
4414+
\end{libverbatim}
4415+
4416+
% ================================================================
4417+
\subsubsection{String Type Functions}
4418+
\index{TStrCat@\texttt{TStrCat} (type function)}
4419+
\index{TNumToStr@\texttt{TNumToStr} (type function)}
4420+
\index[function]{Prelude!TStrCat}
4421+
\index[function]{Prelude!TNumToStr}
4422+
4423+
Prelude defines two type functions for creating or manipulating string types.
4424+
The type function \te{TStrCat} is used to concatenate two string types,
4425+
and \te{TNumToStr} is used to convert a numeric type into a string type.
4426+
43824427
\begin{center}
43834428
\begin{tabular}{|p {1 in}|p{1.5 in}| p{2.0 in}|}
43844429
\hline
4385-
Type Function& Type Relationship& Description\\
4430+
Type Function& Application& Description\\
43864431
\hline
43874432
\hline
43884433
\te{TStrCat}&\verb'TStrCat#(s1,s2)'&Concatenate $s1$ and $s2$\\

0 commit comments

Comments
 (0)