[Haskell-beginners] How best to do this?

Brent Yorgey byorgey at seas.upenn.edu
Mon Apr 29 16:56:43 CEST 2013


On Mon, Apr 29, 2013 at 02:59:29PM +0100, emacstheviking wrote:
> I have built a library for using the Hexwax expandIO-USB chip and I have
> now got some code to drive a stepper motor:
> 
> doOption :: HWHandle -> Flag -> IO ()
> doOption dev (Backward n) = do
>   putStrLn $ "> STEP BACKWARD " ++ (show n)
>   let x = [ stepBit b | b <- [3..0]]
>   return ()
>     where
>       stepBit p b = setBit p b 0 >> setBit p b 1
>         where setBit p b s = HW.setPortBit dev p b s >> stepDelay

The other posted solutions are good, but I also want to make a very
important comment about the above code: it does not actually step any
bits!  All it does is print some stuff.  x is simply a name for a list
of IO actions; it is never used so it just gets garbage collected and
the IO actions are never run.

-Brent



More information about the Beginners mailing list