@@ -1455,7 +1455,7 @@ \subsubsection{SaturatingArith}
1455
1455
1456
1456
\end {verbatim }
1457
1457
1458
- \subsubsection {Alias and NumAlias }
1458
+ \subsubsection {Alias, NumAlias, and StrAlias }
1459
1459
\label {sec-alias }
1460
1460
\index {Alias}
1461
1461
\index {NumAlias}
@@ -4169,15 +4169,14 @@ \subsubsection{Rules}
4169
4169
% ================================================================
4170
4170
\subsection {Operations on Numeric and String Types }
4171
4171
4172
- \subsubsection {Size Relationship/ Provisos }
4172
+ \subsubsection {Size Relationship Provisos }
4173
4173
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)}
4181
4180
4182
4181
4183
4182
@@ -4223,22 +4222,22 @@ \subsubsection{Size Relationship/Provisos}
4223
4222
4224
4223
\subsubsection {Size Relationship Type Functions }
4225
4224
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 )}
4234
4233
\index [function]{Prelude!TAdd}
4235
4234
\index [function]{Prelude!TSub}
4235
+ \index [function]{Prelude!TMul}
4236
+ \index [function]{Prelude!TDiv}
4236
4237
\index [function]{Prelude!TLog}
4237
4238
\index [function]{Prelude!TExp}
4238
- \index [function]{Prelude!TMul}
4239
4239
\index [function]{Prelude!TMax}
4240
4240
\index [function]{Prelude!TMin}
4241
- \index [function]{Prelude!TDiv}
4242
4241
4243
4242
These type functions are used when `` defining'' size relationships between data
4244
4243
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}
4247
4246
\begin {center }
4248
4247
\begin {tabular }{|p {1 in}|p{1.5 in}| p{2.0 in}|}
4249
4248
\hline
4250
- Type Function& Size Relationship & Description\\
4249
+ Type Function& Application & Description\\
4251
4250
\hline
4252
4251
\hline
4253
4252
\te {TAdd}&\verb 'TAdd#(n1,n2) '&Calculate $ n1 + n2 $ \\
@@ -4289,19 +4288,50 @@ \subsubsection{Size Relationship Type Functions}
4289
4288
4290
4289
4291
4290
% ================================================================
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 }
4293
4321
\index {valueof@\texttt {valueof } (pseudo-function of size types)}
4294
4322
\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)}
4296
4325
\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.
4298
4332
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.
4305
4335
4306
4336
\begin {center }
4307
4337
\begin {tabular }{|p{1 in}|p{4.6 in}|}
@@ -4311,7 +4341,7 @@ \subsubsection{valueOf and SizeOf pseudo-functions}
4311
4341
\te {valueOf}& \\
4312
4342
\cline {2-2}
4313
4343
&\begin {libverbatim }
4314
- function Integer valueOf (t) ;
4344
+ function Integer valueOf (numeric type t) ;
4315
4345
\end {libverbatim }
4316
4346
\\
4317
4347
\hline
@@ -4321,24 +4351,28 @@ \subsubsection{valueOf and SizeOf pseudo-functions}
4321
4351
{\bf Examples}
4322
4352
\begin {libverbatim }
4323
4353
module mkFoo (Foo#(n));
4324
- UInt#(n) x;
4325
4354
Integer y = valueOf(n);
4326
4355
endmodule
4327
4356
\end {libverbatim }
4328
4357
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.
4330
4364
4331
4365
\begin {center }
4332
4366
\begin {tabular }{|p{1 in}|p{4.6 in}|}
4333
4367
\hline
4334
4368
& \\
4335
- \te {SizeOf } & Converts a type into a numeric type representing its
4369
+ \te {sizeOf } & Converts a type into a numeric type representing its
4336
4370
bit size.\\
4337
4371
& \\
4338
4372
\cline {2-2}
4339
4373
&\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 )) ;
4342
4376
\end {libverbatim }
4343
4377
\\
4344
4378
\hline
@@ -4347,23 +4381,16 @@ \subsubsection{valueOf and SizeOf pseudo-functions}
4347
4381
4348
4382
{\bf Examples}
4349
4383
\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
4352
4390
\end {libverbatim }
4353
4391
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.
4367
4394
4368
4395
\begin {center }
4369
4396
\begin {tabular }{|p{1 in}|p{4.6 in}|}
@@ -4372,17 +4399,35 @@ \subsubsection{String type pseudo-functions}
4372
4399
\te {stringOf}&Converts a string type into its String value.\\
4373
4400
\cline {2-2}
4374
4401
&\begin {libverbatim }
4375
- function String stringOf (t) ;
4402
+ function String stringOf (string type t) ;
4376
4403
\end {libverbatim }
4377
4404
\\
4378
4405
\hline
4379
4406
\end {tabular }
4380
4407
\end {center }
4381
4408
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
+
4382
4427
\begin {center }
4383
4428
\begin {tabular }{|p {1 in}|p{1.5 in}| p{2.0 in}|}
4384
4429
\hline
4385
- Type Function& Type Relationship & Description\\
4430
+ Type Function& Application & Description\\
4386
4431
\hline
4387
4432
\hline
4388
4433
\te {TStrCat}&\verb 'TStrCat#(s1,s2) '&Concatenate $ s1 $ and $ s2 $ \\
0 commit comments