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. State as function? (martin)
2. Re: State as function? (Daniel Trstenjak)
3. Re: State as function? (martin)
4. Re: iterated function value sequence (Bob Ippolito)
5. Re: State as function? (Karl Voelker)
6. Re: State as function? (Karl Voelker)
7. Re: What does "(# #)" mean? (Emanuel Koczwara)
8. What is a "Monad Comprehension" ? (John M. Dlugosz)
9. Re: What is a "Monad Comprehension" ? (Kim-Ee Yeoh)
----------------------------------------------------------------------
Message: 1
Date: Sun, 06 Apr 2014 15:20:14 +0200
From: martin <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] State as function?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-15
Hello all,
in my program, I have to keep track of the State of a Guitar, i.e. where the
fingers are on the fretboard and which
strings are currently playing. Thus I need to associate some information to
each of the 6 strings.
I started out with assoc lists and hashmaps. However, I found it diffiult to
ensure that all 6 GuitarString have a
something attached and found myself messing with Maybes. In the real world,
there is no way a GuitarString can have "no
state at all", while the HashMap approach would provide this option.
Then I thought, hey I really just need a function from GuitarString to
something, so why not make that function the
state? That was certainly doable, but I still have my doubts whether this is
the correct way of doing such things.
What is particularly worrying is that a state change will most likely affect a
single GuitarString only. So I need to
create a new function which answers the new something for that particular
GuitarString and calls the old function for
strings whose state hasn't changed. So with many state changes, I will get a
deep call hierarchy. Though in the real
world this is unlikely to cause problems, it makes me worry.
What do you think?
------------------------------
Message: 2
Date: Sun, 6 Apr 2014 16:05:14 +0200
From: Daniel Trstenjak <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] State as function?
Message-ID: <20140406140514.GA2213@machine>
Content-Type: text/plain; charset=us-ascii
Hi Martin,
On Sun, Apr 06, 2014 at 03:20:14PM +0200, martin wrote:
> I started out with assoc lists and hashmaps. However, I found it
> diffiult to ensure that all 6 GuitarString have a something attached
> and found myself messing with Maybes. In the real world, there is no
> way a GuitarString can have "no state at all", while the HashMap
> approach would provide this option.
I would start by designing the data structures that represent your
possible states. That way you can also ensure that there can't be
any non representable states.
I really don't now what makes sense in your case, but something like:
data StringState = Resting
| Oscillating
...
data Guitar = Guitar
{ string1 :: StringState
, string2 :: StringState
...
}
If you have worked out the right data structures, then writing
the surrounding code can become quite naturally.
Greetings,
Daniel
------------------------------
Message: 3
Date: Sun, 06 Apr 2014 18:28:54 +0200
From: martin <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] State as function?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Am 04/06/2014 04:05 PM, schrieb Daniel Trstenjak:
>
> data StringState = Resting
> | Oscillating
> ...
>
> data Guitar = Guitar
> { string1 :: StringState
> , string2 :: StringState
> ...
> }
Yes this, and also the information on which fret the finger is.
The problem with this approach is that I end up with two representations of
GuitarString. One is the accessor functions
above, but there is also a datatype GuitarString which I need to express things
like "put your finger on the nth fret of
the mth string".
I found myself mapping between these two representations, which is not hard to
do, but it impairs clarity.
------------------------------
Message: 4
Date: Sun, 6 Apr 2014 09:41:38 -0700
From: Bob Ippolito <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] iterated function value sequence
Message-ID:
<CACwMPm9NFvWz0Z8QCbV_Q5arsYh==bfz4uutoq9+iyb2kqb...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
If zz is top-level, then it doesn't know you'll never refer to it again
(the compiler doesn't *have* to keep this around it's hard to know whether
or not it will).
?> let zz = abs <$> numerator <$> iterate (\x->x^2-7%4) 0
?> print (zz !! 2)
21
?> :sprint zz
zz = _ : _ : 21 : _
Note also that iterate is best when you use all of the values up to where
you want to stop (or at least make sure they get evaluated).
If you want to iterate a specific number of times and just get the result,
perhaps foldl' is the way to do it.
?> abs $ numerator $ foldl' (\x _ -> x^2-7%4) 0 (replicate 7 ())
595096023596888261906480183623645954687
See also:
https://ghc.haskell.org/trac/ghc/ticket/3474
http://stackoverflow.com/questions/8909997/haskell-repeat-a-function-a-large-number-of-times-without-stackoverflow
On Sun, Apr 6, 2014 at 12:44 AM, John M. Dlugosz
<[email protected]>wrote:
> On 4/5/2014 10:55 AM, Bob Ippolito wrote:
>
>> Now, how might I do something like that but "forget" previous values
>> to free up memory?
>>
>>
>> Garbage Collection does that for you. If all the references are gone, the
>> memory can be
>> freed. If you have a specific use in mind I can show you what that looks
>> like.
>>
>>
>> Say,
> zz = abs <$> numerator <$> iterate (\x->x^2-7%4) 0
>
> and at some point I
> print $ zz!!30
>
> How does the GC know that I'll never refer to zz!!n again where n < 30 ?
>
>
> _______________________________________________
> 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/20140406/6eda3a4b/attachment-0001.html>
------------------------------
Message: 5
Date: Sun, 06 Apr 2014 10:39:25 -0700
From: Karl Voelker <[email protected]>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell" <[email protected]>
Subject: Re: [Haskell-beginners] State as function?
Message-ID:
<[email protected]>
Content-Type: text/plain
On Sun, Apr 6, 2014, at 09:28 AM, martin wrote:
> The problem with this approach is that I end up with two representations
> of GuitarString. One is the accessor functions
> above, but there is also a datatype GuitarString which I need to express
> things like "put your finger on the nth fret of
> the mth string".
You could try using an array:
data StringIndex = S1 | S2 | S3 | S4 | S5 | S6 deriving (Eq, Ord, Enum,
Bounded, Read, Show)
type Guitar = Array StringIndex StringState
http://hackage.haskell.org/package/array-0.5.0.0/docs/Data-Array.html
The Enum and Bounded constraints on StringIndex let you do fun things
like:
allStrings = [minBound .. maxBound]
-Karl
------------------------------
Message: 6
Date: Sun, 06 Apr 2014 10:50:02 -0700
From: Karl Voelker <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] State as function?
Message-ID:
<[email protected]>
Content-Type: text/plain
On Sun, Apr 6, 2014, at 10:39 AM, Karl Voelker wrote:
> data StringIndex = S1 | S2 | S3 | S4 | S5 | S6 deriving (Eq, Ord, Enum,
> Bounded, Read, Show)
I should have included the Ix class in the deriving list, so you can use
it as an Array index.
-Karl
------------------------------
Message: 7
Date: Sun, 06 Apr 2014 20:42:03 +0200
From: Emanuel Koczwara <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] What does "(# #)" mean?
Message-ID: <1396809723.9958.4.camel@emanuel-laptop>
Content-Type: text/plain; charset="UTF-8"
Hi,
> Since Emanuel was confused by my meta-quoting of syntax in prose, is there
> some (other)
> standard that's used in this mailing list when using plain text without
> markup?
My response to your question was to impulsive, sorry about that.
Regards,
Emanuel
------------------------------
Message: 8
Date: Mon, 07 Apr 2014 03:33:47 -0500
From: "John M. Dlugosz" <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] What is a "Monad Comprehension" ?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
I know about List Comprehensions, but what is a general Monad Comprehension?
List
Comprehensions are the use of set-builder notation to define a list, so I don't
understand
how that would generalize.
------------------------------
Message: 9
Date: Mon, 7 Apr 2014 15:45:29 +0700
From: Kim-Ee Yeoh <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] What is a "Monad Comprehension" ?
Message-ID:
<capy+zdrdmgeoasgad4uynu8-3ed5ud5xxwslallxgxarzuo...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
On Mon, Apr 7, 2014 at 3:33 PM, John M. Dlugosz <[email protected]>wrote:
> I know about List Comprehensions, but what is a general Monad
> Comprehension? List Comprehensions are the use of set-builder notation to
> define a list, so I don't understand how that would generalize.
Assuming that you have done a search and that you're still stumped, how can
you make the question more specific?
Do you think that quoting specific bits of what you have read might help us
help you more?
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140407/6d01f4c1/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 70, Issue 14
*****************************************