Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  question about shared data types (Brent Yorgey)
   2.  How best to do this? (emacstheviking)
   3. Re:  How best to do this? (Benjamin Edwards)
   4. Re:  How best to do this? (emacstheviking)
   5. Re:  How best to do this? (emacstheviking)


----------------------------------------------------------------------

Message: 1
Date: Mon, 29 Apr 2013 09:44:57 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] question about shared data types
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Mon, Apr 29, 2013 at 11:28:03AM +0100, Ian Knopke wrote:
>
> I've been including newtype Foo in a Common.hs module that is
> included in both, as I would in C or C++. This sort of thing can easily get
> more complicated as the program grows however.

That is exactly what I would do, and is a common practice.  For
example, you will often see a module named something like
'Foo.Bar.Types' which contains declarations of common types which are
used in many other modules.

I am not sure what you mean when you say that this can get complicated
as the program grows.  I have some fairly large packages using this
technique and in practice I have not seen much complication.  Can you
give an example of the sort of complication you mean?

-Brent



------------------------------

Message: 2
Date: Mon, 29 Apr 2013 14:59:29 +0100
From: emacstheviking <[email protected]>
Subject: [Haskell-beginners] How best to do this?
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <caeieuuk1ep5_5mf0q6fonjfuqgrnq9pftczo1rvitpdhfn2...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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-0001.htm>

------------------------------

Message: 3
Date: Mon, 29 Apr 2013 15:07:06 +0100
From: Benjamin Edwards <[email protected]>
Subject: Re: [Haskell-beginners] How best to do this?
To: haskellbeginners <[email protected]>
Message-ID:
        <can6k4ng+3y64mojiaixwub8x3_edewk1eqxvrcwt3hydptk...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

forM_ [0..3] \b -> stepBit b .... ?
On 29 Apr 2013 15:01, "emacstheviking" <[email protected]> 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
> [email protected]
> 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-0001.htm>

------------------------------

Message: 4
Date: Mon, 29 Apr 2013 15:23:19 +0100
From: emacstheviking <[email protected]>
Subject: Re: [Haskell-beginners] How best to do this?
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <caeieuukqq7gbkbp3waab4kszvgvxr7sv-0jbtw4xkhpmekc...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Benjamin, I am sure I tried that but I was hell bent on using a list
comprehension...if it comes to it though I will do it!


On 29 April 2013 15:07, Benjamin Edwards <[email protected]> wrote:

> forM_ [0..3] \b -> stepBit b .... ?
> On 29 Apr 2013 15:01, "emacstheviking" <[email protected]> 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
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130429/dea326a7/attachment-0001.htm>

------------------------------

Message: 5
Date: Mon, 29 Apr 2013 15:37:10 +0100
From: emacstheviking <[email protected]>
Subject: Re: [Haskell-beginners] How best to do this?
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <caeieuu+iitc8mkku3ouf6exw9kk9-y-qn2ebtv81iwvz2k+...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Benjamin,
I have managed to reduce it all to this for which I thank you, it feels
much neater now...

doOption dev (Forward n)  = do
  putStrLn $ "> STEP FORWARD " ++ (show n)
  forM_ [3..0] (\b -> stepBit dev ioPORTA b)

doOption dev (Backward n) = do
  putStrLn $ "> STEP BACKWARD " ++ (show n)
  forM_ [0..3] (\b -> stepBit dev ioPORTA b)

stepBit :: HWHandle -> Word8 -> Word8 -> IO ()
stepBit dev p b = setBit p b 0 >> setBit p b 1
    where
      setBit p b s = HW.setPortBit dev p b s >> stepDelay


I think I will also try to use "forEach_" as well which means I can then
compose is something that passes in [0..3] or [3..0] to the composition...
I may even learn something in the process!
God I love the way that Haskell makes you *want* to reduce things to their
most succint form, even if it hurts along the way.
Only Lisp ever (ha, still does!) made me feel like Haskell does, aka a
total n00b after 28 years in the business! LMAO

Thanks list.



On 29 April 2013 15:07, Benjamin Edwards <[email protected]> wrote:

> forM_ [0..3] \b -> stepBit b .... ?
> On 29 Apr 2013 15:01, "emacstheviking" <[email protected]> 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
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130429/5d7925f0/attachment.htm>

------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 58, Issue 48
*****************************************

Reply via email to