[Haskell-beginners] How best to do this?

Benjamin Edwards edwards.benj at gmail.com
Mon Apr 29 16:07:06 CEST 2013


forM_ [0..3] \b -> stepBit b .... ?
On 29 Apr 2013 15:01, "emacstheviking" <objitsu at gmail.com> 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
>
>
> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130429/cbd38ad0/attachment.htm>


More information about the Beginners mailing list