Send Beginners mailing list submissions to beginners@haskell.org 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 beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: Problem reading sound data from mic with TChan (Christopher Allen) 2. Re: Questions About Rose Trees Analysis (David Thomas) 3. Re: Problem reading sound data from mic with TChan (Martin Vlk) 4. How to nest arbitrary things (martin) ---------------------------------------------------------------------- Message: 1 Date: Sun, 20 Dec 2015 20:01:13 -0600 From: Christopher Allen <c...@bitemyapp.com> To: lukex...@gmail.com, The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Problem reading sound data from mic with TChan Message-ID: <CADnndOo-j4ecuOG1c4b2+jyrmUShL5AnjScVpxeOswqKW=v...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" https://github.com/bitemyapp/blacktip/blob/master/src/Database/Blacktip.hs#L47-L54 :) On Sun, Dec 20, 2015 at 7:38 PM, Luke Iannini <lukex...@gmail.com> wrote: > 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 <mar...@vlkk.cz> 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 >> Beginners@haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Chris Allen Currently working on http://haskellbook.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151220/0e6d023d/attachment-0001.html> ------------------------------ Message: 2 Date: Sun, 20 Dec 2015 18:57:24 -0800 From: David Thomas <davidleotho...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Questions About Rose Trees Analysis Message-ID: <CAJUDvcjojvUJUsG5sYvHtvDOD9-fVmj_CHA-_ed=fcdrfge...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 It seems to me like there might be benefit to special casing the error message when (as in this case) the only thing wrong with an expression is that the resulting type is missing the Show instance implicitly demanded by ghci. On Sun, Dec 20, 2015 at 4:06 AM, Lorenzo Isella <lorenzo.ise...@gmail.com> wrote: > 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 >> <lorenzo.ise...@gmail.com> 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 > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ Message: 3 Date: Mon, 21 Dec 2015 07:07:10 +0000 From: Martin Vlk <mar...@vlkk.cz> To: beginners@haskell.org Subject: Re: [Haskell-beginners] Problem reading sound data from mic with TChan Message-ID: <5677a51e.9060...@vlkk.cz> Content-Type: text/plain; charset=windows-1252 Oh doh, #@!"%^ damn it! ;-) Yes, you are absolutely right, many thanks for the help! Martin Luke Iannini: > 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 <mar...@vlkk.cz> 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 >> Beginners@haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > ------------------------------ Message: 4 Date: Mon, 21 Dec 2015 10:40:28 +0100 From: martin <martin.drautzb...@web.de> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: [Haskell-beginners] How to nest arbitrary things Message-ID: <5677c90c.3010...@web.de> Content-Type: text/plain; charset=utf-8 Hello all, I was trying to model things which can contain other things. This is easy as long as containers and the contained items all can be described in the same fashion. However when I want to model - say - trucks containing boxes containing parcels containing cans and trucks, boxes, parcels and cans are not of the same type, then this nested thing will become a type in its own right and it will be of a different type than trucks containing cans (which are not wrappen in parcels ...) As long as I can squeeze trucks, boxes ... into one type, possibly by using a "container_type" attribute, there is no problem. Is this the only way to do this? Is there an idiom? ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 90, Issue 37 *****************************************