[Haskell-beginners] How best to do this?

emacstheviking objitsu at gmail.com
Mon Apr 29 15:59:29 CEST 2013


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


It feels a little smelly... if I don't assign the result of the list
comprehension to "x" the return type blows at me hence the return(), to get
past the door steward type checker... so what would be the "ideal" way to
just execute my LC to step the bits and then return.

I thought of using "liftIO" but I think that would be "backwards" here if
you catch my drift. I am already in the IO monad as it is, so that has
confused me because liftIO lifts something "into" the IO monad and I am
already there... this project is making me work harder at my Haskell and I
think that once I've completed it I will be much further advanced with it...

So, if anybody cares to suggest more elegant and Haskell like ways to
re-factor the above code I am more than happy to know about it!

All the best,
Sean.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130429/07e5ad5c/attachment.htm>


More information about the Beginners mailing list