Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/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: Questions About Rose Trees Analysis (Lorenzo Isella)
2. Re: Questions About Rose Trees Analysis (Imants Cekusins)
3. Re: Doubts about functional programming paradigm (Rustom Mody)
4. Problem reading sound data from mic with TChan (Martin Vlk)
5. Re: Questions About Rose Trees Analysis (Lorenzo Isella)
6. Re: Questions About Rose Trees Analysis (jean verdier)
7. Re: Doubts about functional programming paradigm (Darren Grant)
8. Re: Problem reading sound data from mic with TChan (Luke Iannini)
----------------------------------------------------------------------
Message: 1
Date: Sun, 20 Dec 2015 13:06:04 +0100
From: Lorenzo Isella <[email protected]>
To: Henk-Jan van Tuyl <[email protected]>
Cc: [email protected]
Subject: Re: [Haskell-beginners] Questions About Rose Trees Analysis
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8; format=flowed
On Thu, Dec 17, 2015 at 12:10:01PM +0100, Henk-Jan van Tuyl wrote:
>On Thu, 17 Dec 2015 11:37:24 +0100, Lorenzo Isella
><[email protected]> wrote:
>:
>>
>>data Rose a = a :> [Rose a]
>>deriving (Eq, Show)
>>
>>and the root can be detected simply as
>>
>>root (a :> rs) = a
>>
>>I would like to have the expression (with the ":>" notation for the
>>Node) of the function to find the children of the root. Example of
>>expected behavior of this function children
>>
>>children (1 :> [2 :> [], 3 :> []]) = [2 :> [], 3 :> []]
>>
>>On top of that, I am trying to get the functions to have the functions
>>
>> size :: Rose a -> Int
>> leaves :: Rose a -> Int
>>
>>that count the number of nodes in a rose tree, respectively the number
>>of leaves (nodes without any children).
>>For the children function, I have tried stuff like
>>
>>children (a :> rs) = rs
>>
>>quite unsuccessfully.
>:
>
>Your definition of children is correct, what is the message you get
>from the compiler/interpreter?
>
>Regards,
>Henk-Jan van Tuyl
Hello,
This is the situation: my script rose.hs is given by
data Rose a = a :> [Rose a]
root (a :> rs) = a
children (a :> rs) = rs
and this is what happens when I load it and apply the children
function on a rose tree
$ ghci
GHCi, version 7.8.4: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :load rose.hs
[1 of 1] Compiling Main ( rose.hs, interpreted )
Ok, modules loaded: Main.
*Main> children (1 :> [2 :> [], 3 :> []])
<interactive>:3:1:
No instance for (Show (Rose t0)) arising from a use of ?print?
In a stmt of an interactive GHCi command: print it
I do not really understand what goes wrong and any suggestion is
appreciated.
Cheers
Lorenzo
------------------------------
Message: 2
Date: Sun, 20 Dec 2015 13:14:56 +0100
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Questions About Rose Trees Analysis
Message-ID:
<CAP1qinZfasbuWyJDXh3fNYF6nVVcZwAy5+N6bxE8WCXV=gl...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
> No instance for (Show (Rose t0)) arising from a use of ?print?
try
data Rose a = a :> [Rose a] deriving Show
------------------------------
Message: 3
Date: Sun, 20 Dec 2015 22:09:22 +0530
From: Rustom Mody <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Doubts about functional programming
paradigm
Message-ID:
<CAJ+TeodiFy_p9xZmofH0CbWgN-1E7LK+=TmY0=bdv4fjxp2...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Wed, Dec 16, 2015 at 1:43 AM, Rein Henrichs <[email protected]>
wrote:
>
> Mr. McIlroy,
>
> FWIW I would love to read more about that McCarthy talk. It
> sounds like an amazing experience.
>
>
No I was not there (in more than one sense!) when that talk happened
About the power of scheme being under-appreciated (even by the authors of
SICP!)
http://blog.languager.org/2013/08/applying-si-on-sicp.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151220/da5eb8a3/attachment-0001.html>
------------------------------
Message: 4
Date: Sun, 20 Dec 2015 17:24:18 +0000
From: Martin Vlk <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Problem reading sound data from mic with
TChan
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Hi, I am working on a little toy project related to controlling graphics
display based on data from the computer microphone.
I am basing the whole thing on concepts from game programming, so I have
a main loop which reads inputs, updates the world state and generates
outputs.
As part of inputs there is microphone. I read data from it using the
pulse-simple library. The "simpleRead" function blocks if there is not
enough data available so I can't use it directly in the main loop or I
risk delays.
So I figured I'll use a separate thread to read from the mic and write
data into a TChan. The main loop in separate thread then can read from
the TChan as needed and test for availability of data to avoid delaying
the main loop.
Here is my current code: http://lpaste.net/147522
The data is written into TChan in the "handleMic" function and read from
the TChan on line 85.
The problem I have is that the TChan never seems to contain any data
when I read from it and that confuses me. Why?
Does anyone see where is my problem?
Many Thanks
Martin
------------------------------
Message: 5
Date: Sun, 20 Dec 2015 20:59:54 +0100
From: Lorenzo Isella <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Questions About Rose Trees Analysis
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii; format=flowed
Dear All,
This is where I stand now. Please consider the short snippet
data Rose a = a :> [Rose a]
deriving (Eq, Show)
root (a :> rs) = a
children (a :> rs) = rs
size :: Rose a -> Int
size (a :> rs) = 1 + (length $ children (a :> rs))
which defines a rose tree structure and the functions to get the
root, the children and the size (i.e. number of nodes) of the rose
tree.
I would like to find the number of leaves (i.e. terminal nodes) in my
rose tree.
Essentially, I need to count the number of "[]" inside my rose tree
definition.
For instance, consider
mytree = (1 :> [2 :> [], 3 :> []])
which has exactly two leaves.
Can anyone help me implement a function to get the number of leaves?
Many thanks
Lorenzo
------------------------------
Message: 6
Date: Mon, 21 Dec 2015 00:22:39 +0100
From: jean verdier <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Questions About Rose Trees Analysis
Message-ID: <[email protected]>
Content-Type: text/plain; charset="UTF-8"
I think that your definition of size is not what you say it is.
I guess that you expect (size (1 :> [2 :> [ 3 :> [] ] ])) to be 3.
To count leaves you may start with something like:
countleaves (_ :> []) = 1
You have then to define countleaves for the case it's not a leaf.
I hope this is of some help.
On Sun, 2015-12-20 at 20:59 +0100, Lorenzo Isella wrote:
> Dear All,
> This is where I stand now. Please consider the short snippet
>
> data Rose a = a :> [Rose a]
> deriving (Eq, Show)
>
> root (a :> rs) = a
>
> children (a :> rs) = rs
>
> size :: Rose a -> Int
>
> size (a :> rs) = 1 + (length $ children (a :> rs))
>
> which defines a rose tree structure and the functions to get the
> root, the children and the size (i.e. number of nodes) of the rose
> tree.
> I would like to find the number of leaves (i.e. terminal nodes) in my
> rose tree.
> Essentially, I need to count the number of "[]" inside my rose tree
> definition.
> For instance, consider
>
> mytree = (1 :> [2 :> [], 3 :> []])
>
> which has exactly two leaves.
> Can anyone help me implement a function to get the number of leaves?
> Many thanks
>
> Lorenzo
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
Message: 7
Date: Sun, 20 Dec 2015 15:27:50 -0800
From: Darren Grant <[email protected]>
To: Haskell Beginners <[email protected]>
Subject: Re: [Haskell-beginners] Doubts about functional programming
paradigm
Message-ID:
<CA+9vpFdPs62bF=arra_ux1wch_cydxt0v+lsw6irqksshsf...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Lacking intentional syntax for function application is much more profound
than I would have expected.
Cheers,
Darren
On Dec 20, 2015 08:39, "Rustom Mody" <[email protected]> wrote:
>
>
> On Wed, Dec 16, 2015 at 1:43 AM, Rein Henrichs <[email protected]>
> wrote:
>
>>
>> Mr. McIlroy,
>>
>> FWIW I would love to read more about that McCarthy talk. It
>> sounds like an amazing experience.
>>
>>
> No I was not there (in more than one sense!) when that talk happened
>
> About the power of scheme being under-appreciated (even by the authors of
> SICP!)
>
> http://blog.languager.org/2013/08/applying-si-on-sicp.html
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151220/e585d102/attachment-0001.html>
------------------------------
Message: 8
Date: Sun, 20 Dec 2015 17:38:49 -0800
From: Luke Iannini <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Problem reading sound data from mic
with TChan
Message-ID:
<cago83cinfnb07gip_4xewdoqoz6rxjh4cjppi9+aytm8qyw...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi Martin,
On line 63 http://lpaste.net/147522#line63, when you do
let sndChan = newTChan
you're not actually creating a new TChan, but rather creating a
reference to the STM action that creates new TChans.
So this means that e.g. on line 71 http://lpaste.net/147522#line71,
you are creating a new channel every time with
ch <- sndChan
Instead, you want to do:
sndChan <- newTChanIO
(or,
sndChan <- atomically newTChan
)
And then pass that value to your other functions, which will just take
TChan [Int32] rather than STM (TChan [Int32])
Here's what I mean:
http://lpaste.net/diff/147522/147557
Hope that helps!
On Sun, Dec 20, 2015 at 9:24 AM, Martin Vlk <[email protected]> wrote:
> Hi, I am working on a little toy project related to controlling graphics
> display based on data from the computer microphone.
>
> I am basing the whole thing on concepts from game programming, so I have
> a main loop which reads inputs, updates the world state and generates
> outputs.
>
> As part of inputs there is microphone. I read data from it using the
> pulse-simple library. The "simpleRead" function blocks if there is not
> enough data available so I can't use it directly in the main loop or I
> risk delays.
>
> So I figured I'll use a separate thread to read from the mic and write
> data into a TChan. The main loop in separate thread then can read from
> the TChan as needed and test for availability of data to avoid delaying
> the main loop.
>
> Here is my current code: http://lpaste.net/147522
>
> The data is written into TChan in the "handleMic" function and read from
> the TChan on line 85.
>
> The problem I have is that the TChan never seems to contain any data
> when I read from it and that confuses me. Why?
>
> Does anyone see where is my problem?
>
> Many Thanks
> Martin
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151220/1ef882fe/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 90, Issue 36
*****************************************