user1130: I feel like this should be pretty easy, but I'm stumped. How can I use a slot number as a token name?
I'm currently trying to encode the slot integer as a ByteString:
slotNumberTokenName :: TokenName
slotNumberTokenName = TokenName { unTokenName = encode $ getSlot slot }

but I get the error
    • Couldn't match expected type ‘ByteString’
                  with actual type ‘bytestring-0.10.12.0:Data.ByteString.Lazy.Internal.ByteString’
      NB: ‘bytestring-0.10.12.0:Data.ByteString.Lazy.Internal.ByteString’
            is defined in ‘Data.ByteString.Lazy.Internal’
          ‘ByteString’ is defined in ‘Data.ByteString.Internal’
    • In the ‘unTokenName’ field of a record
      In the expression: TokenName {unTokenName = encode $ getSlot slot}
      In an equation for ‘slotNumberTokenName’:
          slotNumberTokenName
            = TokenName {unTokenName = encode $ getSlot slot}
    |
153 |     slotNumberTokenName = TokenName { unTokenName = encode $ getSlot slot }
    | 

I am using Data.Aeson.encode, so maybe there is a different function to do that conversion.
Anyhow, any help would be appreciated. Been looking at this for longer than I'd like to admit.

user1142: This can be done with Data.Binary. See https://stackoverflow.com/a/2284193/10069673
Another possibility would be to convert the int to a string and then convert the string to a ByteString.

int to string: https://stackoverflow.com/a/2784280/10069673
string to ByteString: https://stackoverflow.com/a/40491001/10069673


user2042: I've just run this in the REPL with success. Not sure if it is the best way, though.
TokenName { unTokenName = Data.ByteString.Char8.pack $ show (toInteger (getSlot 1)) }


1130: <p>I feel like this should be pretty easy, but I'm stumped. How can I use a slot number as a token name?</p>
<p>I'm currently trying to <code>encode</code> the slot <code>integer</code> as a <code>ByteString</code>:</p>
<pre><code>slotNumberTokenName :: TokenName
slotNumberTokenName = TokenName { unTokenName = encode $ getSlot slot }
</code></pre>
<p>but I get the error</p>
<pre><code>    • Couldn't match expected type ‘ByteString’
                  with actual type ‘bytestring-0.10.12.0:Data.ByteString.Lazy.Internal.ByteString’
      NB: ‘bytestring-0.10.12.0:Data.ByteString.Lazy.Internal.ByteString’
            is defined in ‘Data.ByteString.Lazy.Internal’
          ‘ByteString’ is defined in ‘Data.ByteString.Internal’
    • In the ‘unTokenName’ field of a record
      In the expression: TokenName {unTokenName = encode $ getSlot slot}
      In an equation for ‘slotNumberTokenName’:
          slotNumberTokenName
            = TokenName {unTokenName = encode $ getSlot slot}
    |
153 |     slotNumberTokenName = TokenName { unTokenName = encode $ getSlot slot }
    | 
</code></pre>
<p>I am using <code>Data.Aeson.encode</code>, so maybe there is a different function to do that conversion.</p>
<p>Anyhow, any help would be appreciated. Been looking at this for longer than I'd like to admit.</p>
 1142: <p>This can be done with <code>Data.Binary</code>. See <a href="https://stackoverflow.com/a/2284193/10069673">https://stackoverflow.com/a/2284193/10069673</a></p>
<p>Another possibility would be to convert the <code>int</code> to a <code>string</code> and then convert the <code>string</code> to a <code>ByteString</code>.</p>
<ul>
<li><code>int</code> to <code>string</code>: <a href="https://stackoverflow.com/a/2784280/10069673">https://stackoverflow.com/a/2784280/10069673</a></li>
<li><code>string</code> to <code>ByteString</code>: <a href="https://stackoverflow.com/a/40491001/10069673">https://stackoverflow.com/a/40491001/10069673</a></li>
</ul>
 2042: <p>I've just run this in the REPL with success. Not sure if it is the best way, though.</p>
<pre><code>TokenName { unTokenName = Data.ByteString.Char8.pack $ show (toInteger (getSlot 1)) }
</code></pre>
