title: Using serial port interactively with Haskell
body: <p>I'm trying to send a message via the serial port to a Lego NXT using Haskell's interactive mode but I cannot figure out how to use the <a href="http://hackage.haskell.org/packages/archive/serialport/0.4.5/doc/html/System-Hardware-Serialport.html" rel="nofollow">serialport</a> functions correctly.</p>
  
  <p>I have a message that should play a tone on the NXT which is of type <code>ByteString</code></p>
  
  <pre><code>&gt; let message = pack ([6, 0 ,0, 3, 224, 1, 208, 7]::[Word8])
  </code></pre>
  
  <p>I can open the serial port using <code>openSerial</code>.</p>
  
  <pre><code>openSerial :: FilePath -&gt; SerialPortSettings -&gt; IO SerialPort
  &gt; let mybrick = openSerial "/dev/tty.NXT-DevB" defaultSerialSettings
  </code></pre>
  
  <p>But then I get stuck. How should I use the <code>send</code> function? </p>
  
  <pre><code>send :: SerialPort -&gt; B.ByteString -&gt; IO Int
  &gt; send mybrick message
  </code></pre>
  
  <p>This gives my the following error message.</p>
  
  <pre><code>&lt;interactive&gt;:31:6:
      Couldn't match expected type `SerialPort'
                  with actual type `IO SerialPort'
      In the first argument of `send', namely `mybrick'
      In the expression: send mybrick message
      In an equation for `it': it = send mybrick message
  </code></pre>