[Haskell-beginners] How best to do this?
emacstheviking
objitsu at gmail.com
Mon Apr 29 17:44:44 CEST 2013
ROFLCOPTER indeed Batman!
I had no idea of that... I just *assumed* (usual rules apply I guess) that
[3..0] was the "opposite" of [0..3] but sure enough a wuicj ghci session
reveals the bitter truth!
Thanks again... i can see that it's not just me that is too lazy at times.
I guess writing [3,2..0] will do for now but is that a bug or is there some
other reasoning behind it?
We live and learn, well, I live anyway...
:)
On 29 April 2013 16:37, David McBride <toad3k at gmail.com> wrote:
> One other gotcha. I don't know why it is this way, but [3..0]
> evaluates to []. I have no idea why reverse notation is not allowed.
> But you can just manually reverse it or you can go [3,2..0].
>
> On Mon, Apr 29, 2013 at 11:26 AM, emacstheviking <objitsu at gmail.com>
> wrote:
> > damn that lazy evaluation! LMAO ...a good point brent and yuo have no
> doubt
> > saved me hours of head scratching this evening when I try out the "new
> > improved software". Oh dear oh dear oh dear...
> >
> > doOption dev (Forward n) = do
> > putStrLn $ "> STEP FORWARD " ++ (show n)
> > stepBits dev ioPORTA [3..0]
> >
> >
> > doOption dev (Backward n) = do
> > putStrLn $ "> STEP BACKWARD " ++ (show n)
> > stepBits dev ioPORTA [0..3]
> >
> > stepBits dev port = mapM_ stepIt
> > where stepIt bit = mapM_ (\s -> HW.setPortBit dev port bit s >>
> stepDelay)
> > [0,1]
> >
> > I now have the above as my current "final" implementation... hopefully
> that
> > *does* do what I think it does because mapM_ is driving it and will cause
> > evaluation of the actions?
> >
> >
> >
> >
> > On 29 April 2013 15:56, Brent Yorgey <byorgey at seas.upenn.edu> wrote:
> >>
> >> 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
> >>
> >> _______________________________________________
> >> Beginners mailing list
> >> Beginners at haskell.org
> >> http://www.haskell.org/mailman/listinfo/beginners
> >
> >
> >
> > _______________________________________________
> > Beginners mailing list
> > Beginners at haskell.org
> > http://www.haskell.org/mailman/listinfo/beginners
> >
>
> _______________________________________________
> 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/34c998f0/attachment.htm>
More information about the Beginners
mailing list