forM_ [0..3] \b -> stepBit b .... ?
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.
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners