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: Can't cast an IO String to s Astring (Rein Henrichs)
2. Re: Can't cast an IO String to s Astring (Rein Henrichs)
3. Re: Processing data from microphone interactively
(Heinrich Apfelmus)
4. Ignore in import (Mike Houghton)
----------------------------------------------------------------------
Message: 1
Date: Fri, 23 Oct 2015 17:16:09 +0000
From: Rein Henrichs <[email protected]>
To: chanti houda <[email protected]>, The Haskell-Beginners
Mailing List - Discussion of primarily beginner-level topics related
to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Can't cast an IO String to s Astring
Message-ID:
<CAJp6G8wozRpuVWtKYKuB43quAg==tzcov5tklyxcoa7ohcw...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
You can't transform an IO String into a String. This is one of the purposes
of monads: to make it possible to work with things like IO, where it is
impossible to turn an IO a into an a. The result of performing an IO action
can be *bound* using (>>=) or <- in do notation so that the String is
available for the rest of the computation:
do
f <- readFile "ctrl.txt"
Right r <- parseCtrl f
cherchectrl r "A01"
Note that there's no need to wrap identifiers in (): (r) is the same as r,
(rez) is the same as rez. And there's no need to say do { let r =
something; return r }. You can just say do { something }.
On Fri, Oct 23, 2015 at 8:32 AM chanti houda <[email protected]> wrote:
> Hello, I'm writing a Haskell code which consists to read a text file,
> parse it and thansform the parsing result on a specific language.
> I have a function *affiche *which takes a data type Ctrl and returns a
> String. This is the transformation funtion.
> I have also anothe function parsctrl, which parse the contents of a text
> file ("ctrl.txt") and after looks for a specific value ("A01") in the parse
> result (function *c**herchectrl*).
> I need to use the result of the *parsectrl *function in another function
> *fc*.
> The code is composed of three functions
>
>
>
> parsectrl = do
> f <- readFile "ctrl.txt"
> let Right r = parse parseCtrl " " f
> let rez =cherchectrl ( r) "A01"
> return (rez)
>
> fc[] =[]
> fc((door,[(all,v1),(alt,v2),(lint,v3),(w,v4),(r,v5),(loc,v6),(
> etat,v7),(ruin,v8)]):ls ) = ("&OUV ID='"++door ++"', ALLEGE="++show((moi
> v1)/1000)++", LINTEAU="++show((moi v3)/1000)++", LARGEUR="++show((moi
> v4)/1000)++", COEF=0.7, ALT="++show((moi v2)/1000)++", LOCIDS='"++v6++"',
> CTRLID='"++ v7++"', CTRLID_RUIN='"++ v8++" /" ++"\n" ++"&CTRL
> ID='"++v7++"', " ++ "ON_INI=.FALSE., DURATION=0 / \n"++"&CTRL
> ID='"++v8++"', LOCID='"++ ((parses("'"++v6++"'"))!!0) ++
> *affiche(parsectrl)*++ " / \n\n" )++fc(ls)
>
> The parsectrl returns an IO String, but the function affiche needs a
> String as input and even when I tried to adapt the affiche function to take
> an IO String -> String I can't.
> the result of fc must be a String too.
>
> The IO String comes from the parsectrl function.
> Can you help me to solve this problem: how can I transform an IO String to
> a String.
>
> Thank you by advance.
>
>
>
>
> _______________________________________________
> 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/20151023/eacf0a43/attachment-0001.html>
------------------------------
Message: 2
Date: Fri, 23 Oct 2015 17:17:23 +0000
From: Rein Henrichs <[email protected]>
To: chanti houda <[email protected]>, The Haskell-Beginners
Mailing List - Discussion of primarily beginner-level topics related
to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Can't cast an IO String to s Astring
Message-ID:
<cajp6g8wd_cz2oz3jfgpsx-v-sf0oaus57+opn51ww96gk_m...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Or rather, you can just say do { return something } or do { return $
something } of "something" is a more complicated expression.
On Fri, Oct 23, 2015 at 10:16 AM Rein Henrichs <[email protected]>
wrote:
> You can't transform an IO String into a String. This is one of the
> purposes of monads: to make it possible to work with things like IO, where
> it is impossible to turn an IO a into an a. The result of performing an IO
> action can be *bound* using (>>=) or <- in do notation so that the String
> is available for the rest of the computation:
>
> do
> f <- readFile "ctrl.txt"
> Right r <- parseCtrl f
> cherchectrl r "A01"
>
> Note that there's no need to wrap identifiers in (): (r) is the same as r,
> (rez) is the same as rez. And there's no need to say do { let r =
> something; return r }. You can just say do { something }.
>
> On Fri, Oct 23, 2015 at 8:32 AM chanti houda <[email protected]> wrote:
>
>> Hello, I'm writing a Haskell code which consists to read a text file,
>> parse it and thansform the parsing result on a specific language.
>> I have a function *affiche *which takes a data type Ctrl and returns a
>> String. This is the transformation funtion.
>> I have also anothe function parsctrl, which parse the contents of a text
>> file ("ctrl.txt") and after looks for a specific value ("A01") in the parse
>> result (function *c**herchectrl*).
>> I need to use the result of the *parsectrl *function in another function
>> *fc*.
>> The code is composed of three functions
>>
>>
>>
>> parsectrl = do
>> f <- readFile "ctrl.txt"
>> let Right r = parse parseCtrl " " f
>> let rez =cherchectrl ( r) "A01"
>> return (rez)
>>
>> fc[] =[]
>> fc((door,[(all,v1),(alt,v2),(lint,v3),(w,v4),(r,v5),(loc,v6),(
>> etat,v7),(ruin,v8)]):ls ) = ("&OUV ID='"++door ++"', ALLEGE="++show((moi
>> v1)/1000)++", LINTEAU="++show((moi v3)/1000)++", LARGEUR="++show((moi
>> v4)/1000)++", COEF=0.7, ALT="++show((moi v2)/1000)++", LOCIDS='"++v6++"',
>> CTRLID='"++ v7++"', CTRLID_RUIN='"++ v8++" /" ++"\n" ++"&CTRL
>> ID='"++v7++"', " ++ "ON_INI=.FALSE., DURATION=0 / \n"++"&CTRL
>> ID='"++v8++"', LOCID='"++ ((parses("'"++v6++"'"))!!0) ++
>> *affiche(parsectrl)*++ " / \n\n" )++fc(ls)
>>
>> The parsectrl returns an IO String, but the function affiche needs a
>> String as input and even when I tried to adapt the affiche function to take
>> an IO String -> String I can't.
>> the result of fc must be a String too.
>>
>> The IO String comes from the parsectrl function.
>> Can you help me to solve this problem: how can I transform an IO String
>> to a String.
>>
>> Thank you by advance.
>>
>>
>>
>>
>> _______________________________________________
>> 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/20151023/6945b761/attachment-0001.html>
------------------------------
Message: 3
Date: Sat, 24 Oct 2015 11:40:28 +0200
From: Heinrich Apfelmus <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Processing data from microphone
interactively
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
Hello Martin,
in digital signal processing (DSP), audio samples are traditionally
processed in *blocks*. Typical blocks sizes for real-time processing are
64, 128 or 256 bytes.
The reason for this is that audio processing is a performance-sensitive
task. If your code is too slow, then it cannot process all audio in time
and there will be jitter. Typically, the operations that are applied to
a single block are fairly limited (mixing, convolution, ...) and can be
optimized into a tight loop, which you can then reuse as a "black box".
In contrast, operations that act on blocks (envelopes, ...) are more
open-ended and you would have to pay attention to optimizing them each
and every time you write a program.
This is related to the concepts of "audio rate" and "control rate". The
former is the frequency at which audio is sampled, i.e. the frequency
"within" a block, while the latter corresponds to more coarse-grained
operations, that are approximately the same on every block.
For you, this means that you probably want to call the `simpleRead`
function with a block size of 128 and process each block individually
before requesting the next. If individual processing proves too slow,
you will have to use data structures that are closer to the machine, and
call the `simpleReadRaw` function instead.
Best regards,
Heinrich Apfelmus
--
http://apfelmus.nfshost.com
Martin Vlk wrote:
> Hi,
> I am looking at reading sound from a microphone and controlling some
> other activity based on the sound data as they come. The motivation for
> this is writing some interactive animated graphics controlled by
> properties of the sound from mic.
>
> I am using the pulseaudio-simple library to read sound from the computer
> mic and that works fine. However the library function basically returns
> sound samples as a list of predefined length and this is not well suited
> for the kind of real-time processing I need.
>
> I am looking for advice on what would be a good idiomatic way to design
> such a program in Haskell.
>
> From some research I am imagining I need something like the conduit
> library to connect the sound data to other parts of my program, but I am
> not sure how that would work or if it is a good idea in the first place.
>
> Or should I use some of the FRP libraries for this purpose?
> Or some other approach?
>
> I'd appreciate some advice on the direction to take.
>
> Many Thanks
> Martin
------------------------------
Message: 4
Date: Sat, 24 Oct 2015 12:55:59 +0100
From: Mike Houghton <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Ignore in import
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Hi,
I?m reading Typeclassopdedia and an exercise is
"A good exercise is to implement Functor instances for Either e, ((,) e), and
((->) e).?
so I have
instance Functor ((,) a) where
fmap = undefined
which gives compiler error
Duplicate instance declarations:
instance Functor ((,) a)
-- Defined at /Users/mike/haskell/FingerTrees/M.hs:65:10
instance Functor ((,) a) -- Defined in ?GHC.Base?
so I added
import GHC.Base hiding ((,))
but I still get the error.
Where am I going wrong?
Many thanks
Mike
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 88, Issue 21
*****************************************