fromInteger

Overview
The fromInteger function converts an Integer into an element of  datatype data_t.  Whenever you write an integer literal in BSV (such as "0" or "1") there is an implied fromInteger function applied to it, which turns the literal into the type you are using, (such as Int, UInt, Bit, etc.). 

The fromInteger function is defined in the Literal typeclass.  By defining an instance of Literal for your own datatypes, you can create values from literals just as for these predefined types.

Example


 function foo (Vector#(n,int) xs) provisos (Log#(n,k));
    Integer maxindex = valueof(n) - 1;
    Int#(k) index;
    index = fromInteger(maxindex);
    ...
 endfunction
Comments