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. reactiva-banana : how to implement a certain type of
throttling (Miguel Negrao)
2. Re: How to solve this using State Monad? (Miguel Negrao)
3. Re: How to solve this using State Monad? (Ertugrul S?ylemez)
4. Re: How to solve this using State Monad? (Ertugrul S?ylemez)
5. Re: How to solve this using State Monad? (damodar kulkarni)
----------------------------------------------------------------------
Message: 1
Date: Sat, 2 Jun 2012 12:38:15 +0100
From: Miguel Negrao <[email protected]>
Subject: [Haskell-beginners] reactiva-banana : how to implement a
certain type of throttling
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252
Hi list,
I would like to implement a certain type of throttling of events in
reactive-banana. It should work such that an event is not let through if
arrives at less then delta seconds from the last event that passed through. If
it is not let through then it is stored and is fired after delta seconds from
the last fired event.
Below is a program that implements this for lists of time stamped numbers.
Would it be possible to translate this to reactive-banana ?
Also, in reactive-banana how do I fire an event x seconds after some other
event comes in. The way I would do it in scala?s reactive-web is to start a
timer that fires x seconds after it is started when an event comes in using
dynamic event switching . It seems to me this would not be possible in
reactive-banana because starting a timer is an IO operation, so I assume it
can?t be done inside the event/behavior logic, right ?
best,
Miguel Negr?o
module Main where
import Data.List
-- 1 second throtling
-- logic is to never output a value before 1 second has passed since last value
was outputed.
main :: IO()
main = print $ test [ (0.0, 1.0), (1.1, 2.0), (1.5,3.0), (1.7,4.0), (2.2, 5.0)
]
--should output [ (0.0, 1.0), (1.1, 2.0), (2.1,4.0), (3.1, 5.0) ]
test :: [(Double,Double)] -> [(Double,Double)]
test list = g v (concat xs)
where
(v, xs) = mapAccumL f (-50,Nothing) list
g (t, Just x) ys = ys ++ [ (t+1,x) ]
g _ ys = ys
f (lasttime, Just holdvalue) (t,x) = if t > (lasttime+1) then
if t > (lasttime + 2) then
( (t, Nothing), [
(lasttime+1,holdvalue), (t,x)] )
else ( (lasttime+1, Just x) , [
(lasttime+1,holdvalue) ] )
else
( (lasttime, Just x), [] )
f (lasttime, Nothing) (t,x) = if t > (lasttime+1) then
( (t,Nothing) , [ (t, x ) ] )
else ( (lasttime, Just x), [] )
------------------------------
Message: 2
Date: Sat, 2 Jun 2012 12:42:38 +0100
From: Miguel Negrao <[email protected]>
Subject: Re: [Haskell-beginners] How to solve this using State Monad?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252
A 31/05/2012, ?s 17:18, Ertugrul S?ylemez escreveu:
> Miguel Negrao <[email protected]> wrote:
>
>> Because of those posts I spent my morning reading about arrows which
>> seems a quite interesting concept, although couldn?t yet see what is
>> best for ( I would be curious to learn it in order to try out Yampa).
>> I have to say that the resources I found to learn about arrows on the
>> net were a bit disorganized. This page is really well done
>> http://en.wikibooks.org/wiki/Haskell/Understanding_arrows but then
>> because I don?t know much about parsers I couldn?t really progress
>> through the second half.
>
> I have started an arrow tutorial which many people found easy to follow.
> It's not finished yet, but since so many people found it useful I'm
> sharing that unfinished tutorial:
>
> <http://ertes.de/new/tutorials/arrows.html>
>
> It answers the most important questions: What? Why? How? To some
> extent it also answers: When? But I have to work on that question.
> The basics of the automaton arrow are covered, but when I find time I
> will extend the tutorial to cover Auto in full. Finally I also intend
> to cover a powerful generalization of Auto: the wire arrow, which is
> the basis of the Netwire AFRP library.
I found your tutorial very enlightening. I think I kind of got more or less the
main idea, but I need to try some code to get a feel for it. I mostly program
audio related stuff and arrows seem perfect for defining audio synthesis (I
already saw some attempts at this with Yampa). I see a lot of similarities
between arrows and the Faust audio synthesis languages (perhaps it?s the same
core idea ?) http://faust.grame.fr/.
best,
Miguel Negr?o
------------------------------
Message: 3
Date: Sat, 2 Jun 2012 13:56:15 +0200
From: Ertugrul S?ylemez <[email protected]>
Subject: Re: [Haskell-beginners] How to solve this using State Monad?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Miguel Negrao <[email protected]> wrote:
> I mostly program audio related stuff and arrows seem perfect for
> defining audio synthesis (I already saw some attempts at this with
> Yampa).
If what you want to define is a monad, you should make it a monad.
Arrows are there because of the limitations of monads. Monads, while
being less general, are more expressive.
If you find that what you want is an arrow, you usually want to make it
an applicative functor as well. Applicative style combined with the
Category class gives much more declarative descriptions of the same
thing (and usually also with higher performance).
This is something I wanted to cover in a later chapter in my tutorial,
but yeah -- it's not finished yet. =)
> I see a lot of similarities between arrows and the Faust audio
> synthesis languages (perhaps it?s the same core idea ?)
> http://faust.grame.fr/.
Yes, that looks like functional reactive programming. You can do that
with Netwire for example. In fact the code samples can be translated
almost 1:1 to Netwire.
Greets,
Ertugrul
--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120602/9ab84865/attachment-0001.pgp>
------------------------------
Message: 4
Date: Sat, 2 Jun 2012 14:02:50 +0200
From: Ertugrul S?ylemez <[email protected]>
Subject: Re: [Haskell-beginners] How to solve this using State Monad?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
Rustom Mody <[email protected]> wrote:
> > I have started an arrow tutorial which many people found easy to
> > follow. It's not finished yet, but since so many people found it
> > useful I'm sharing that unfinished tutorial:
> >
> > <http://ertes.de/new/tutorials/arrows.html>
> >
> > It answers the most important questions: What? Why? How? To some
> > extent it also answers: When? But I have to work on that question.
>
> As usual this is useful and I'll be studying it in more detail. For
> now a general question: What do you think of *teaching* Haskell
> replacing monads with arrows in the early introduction?
According to my experience the same rule that applies to monads also
applies to arrows. In other words: If you can teach monads, you likely
also can teach arrows. If you can't teach monads, don't try to teach
arrows either.
My current position is that understanding applicative functors and
monads makes it much easier to learn arrows. But there is also strong
evidence that teaching arrows first might be useful, building on the
correspondence between Category+Applicative and Arrow. I have not
tried this though.
About my approach to teaching monads there has been a discussion on
Reddit recently:
<http://www.haskell.org/pipermail/haskell-cafe/2012-May/101338.html>
<http://www.reddit.com/r/haskell/comments/u04vp/building_intuition_for_monads_without_mentioning/>
Greets,
Ertugrul
--
Key-ID: E5DD8D11 "Ertugrul Soeylemez <[email protected]>"
FPrint: BD28 3E3F BE63 BADD 4157 9134 D56A 37FA E5DD 8D11
Keysrv: hkp://subkeys.pgp.net/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120602/32a3072e/attachment-0001.pgp>
------------------------------
Message: 5
Date: Sun, 3 Jun 2012 04:59:19 +0530
From: damodar kulkarni <[email protected]>
Subject: Re: [Haskell-beginners] How to solve this using State Monad?
To: Ertugrul S?ylemez <[email protected]>
Cc: [email protected]
Message-ID:
<cad5hsyqblcqedaku6ojszqfsmj4mdmp8rhw+aj3k5bj56ks...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Hello,
I find this whole discussion very much helpful.
Ertugrul said:
Monads, while being less general, are more expressive.
>
This statement is rather counter-intuitive for me.
Here is another statement regarding generality and expressiveness:
If we consider DFA and PDA, for instance, PDA is more general and more
expressive than DFA.
Can we say that because PDA is more general than DFA, PDA is more
expressive than DFA.
As per the normal understanding the more general a machine becomes, the
more expressive it is.
So, in what exact sense are you using the terms "general" and "expressive"
w.r.t. Monads and Arrows?
Another thing:
- Is it because Monads are more expressive they are more difficult to
compose (as is the case of the DFA automaton) ?
- Is it because Arrows are less expressive they are easier to compose ?
But then, a more general thing will make it more difficult for us to make
it composible in a yet larger scheme of things.
Am I missing something here?
Thanks and regards,
-Damodar Kulkarni
On Sat, Jun 2, 2012 at 5:32 PM, Ertugrul S?ylemez <[email protected]> wrote:
> Rustom Mody <[email protected]> wrote:
>
> > > I have started an arrow tutorial which many people found easy to
> > > follow. It's not finished yet, but since so many people found it
> > > useful I'm sharing that unfinished tutorial:
> > >
> > > <http://ertes.de/new/tutorials/arrows.html>
> > >
> > > It answers the most important questions: What? Why? How? To some
> > > extent it also answers: When? But I have to work on that question.
> >
> > As usual this is useful and I'll be studying it in more detail. For
> > now a general question: What do you think of *teaching* Haskell
> > replacing monads with arrows in the early introduction?
>
> According to my experience the same rule that applies to monads also
> applies to arrows. In other words: If you can teach monads, you likely
> also can teach arrows. If you can't teach monads, don't try to teach
> arrows either.
>
> My current position is that understanding applicative functors and
> monads makes it much easier to learn arrows. But there is also strong
> evidence that teaching arrows first might be useful, building on the
> correspondence between Category+Applicative and Arrow. I have not
> tried this though.
>
> About my approach to teaching monads there has been a discussion on
> Reddit recently:
>
> <http://www.haskell.org/pipermail/haskell-cafe/2012-May/101338.html>
> <
> http://www.reddit.com/r/haskell/comments/u04vp/building_intuition_for_monads_without_mentioning/
> >
>
>
> Greets,
> Ertugrul
>
> --
> Key-ID: E5DD8D11 "Ertugrul Soeylemez <[email protected]>"
> FPrint: BD28 3E3F BE63 BADD 4157 9134 D56A 37FA E5DD 8D11
> Keysrv: hkp://subkeys.pgp.net/
>
> _______________________________________________
> 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/20120603/fe85283f/attachment-0001.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 48, Issue 2
****************************************