Issue installing reactive-banana-5.0.0.1

Hi It appears I can’t install reactive-banana-5.0.0.1: cabal install reactive-banana Resolving dependencies... cabal: cannot configure mtl-2.1. It requires transformers ==0.3.* For the dependency on transformers ==0.3.* there are these packages: transformers-0.3.0.0. However none of them are available. transformers-0.3.0.0 was excluded because reactive-banana-0.5.0.1 requires transformers ==0.2.* How can I solve this ? thank you, Miguel

try cabal install reactive-banana --constraint='mtl < 2.1' -Brent On Fri, Apr 27, 2012 at 11:19:39PM +0100, Miguel Negrao wrote:
Hi
It appears I can’t install reactive-banana-5.0.0.1:
cabal install reactive-banana Resolving dependencies... cabal: cannot configure mtl-2.1. It requires transformers ==0.3.* For the dependency on transformers ==0.3.* there are these packages: transformers-0.3.0.0. However none of them are available. transformers-0.3.0.0 was excluded because reactive-banana-0.5.0.1 requires transformers ==0.2.*
How can I solve this ?
thank you, Miguel
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Miguel Negrao wrote:
Hi
It appears I can’t install reactive-banana-5.0.0.1:
cabal install reactive-banana Resolving dependencies... cabal: cannot configure mtl-2.1. It requires transformers ==0.3.* For the dependency on transformers ==0.3.* there are these packages: transformers-0.3.0.0. However none of them are available. transformers-0.3.0.0 was excluded because reactive-banana-0.5.0.1 requires transformers ==0.2.*
How can I solve this ?
I have uploaded reactive-banana-0.5.0.2 which relaxes the version constraint on the transformers package. Try the new version. Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com

A 28/04/2012, às 10:14, Heinrich Apfelmus escreveu:
Miguel Negrao wrote:
Hi It appears I can’t install reactive-banana-5.0.0.1: cabal install reactive-banana Resolving dependencies... cabal: cannot configure mtl-2.1. It requires transformers ==0.3.* For the dependency on transformers ==0.3.* there are these packages: transformers-0.3.0.0. However none of them are available. transformers-0.3.0.0 was excluded because reactive-banana-0.5.0.1 requires transformers ==0.2.* How can I solve this ?
I have uploaded reactive-banana-0.5.0.2 which relaxes the version constraint on the transformers package. Try the new version.
Ok, it installs now, thanks. I had a try again at running the examples of reactive-banana-wx. I unpacked reactive-banana-wx-0.5.0.0. I have installed wx and wxcore version 0.13.1, that’s what I managed to install at some point (I think there were some issue with OSX Lion on previous versions). So I changed the cabal setup of reactive-banana-wx-0.5.0.0 to wx==0.13.1, wxcore==0.13.1 and then did 'cabal install -fbuildExamples’ and everything builds. Most of the examples run fine, although the resize of the window is completely hacky, all the widgets assume strange proportion and become almost unusable (http://img440.imageshack.us/img440/1149/capturadeecr20120428s14.png) . The asteroids app (which was the one I wanted to have look at) the window becomes just a couple pixels, so I can’t see anything (http://img33.imageshack.us/img33/1149/capturadeecr20120428s14.png). Is there a problem in using wx 0.13.1 ? Btw, wx 0.90 "Builds and runs cleanly on 64 bit platforms (particularly MacOS X Lion)”. Would reactive-banana-wx work with wx0.9.0 ? best, Miguel

Miguel Negrao wrote:
I had a try again at running the examples of reactive-banana-wx. I unpacked reactive-banana-wx-0.5.0.0. I have installed wx and wxcore version 0.13.1, that’s what I managed to install at some point (I think there were some issue with OSX Lion on previous versions). So I changed the cabal setup of reactive-banana-wx-0.5.0.0 to wx==0.13.1, wxcore==0.13.1 and then did 'cabal install -fbuildExamples’ and everything builds. Most of the examples run fine, although the resize of the window is completely hacky, all the widgets assume strange proportion and become almost unusable (http://img440.imageshack.us/img440/1149/capturadeecr20120428s14.png) . The asteroids app (which was the one I wanted to have look at) the window becomes just a couple pixels, so I can’t see anything (http://img33.imageshack.us/img33/1149/capturadeecr20120428s14.png). Is there a problem in using wx 0.13.1 ? Btw, wx 0.90 "Builds and runs cleanly on 64 bit platforms (particularly MacOS X Lion)”. Would reactive-banana-wx work with wx0.9.0 ?
Ah, it looks like your version of wx got linked with wxWidgets 2.9.3 instead of wxWidgets 2.8 . This introduces various issues, in particular the ones you ran into. If you just want to try a few examples with wxWidgets 2.9.3, you can install reactive-banana-0.6.0.0 and the corresponding -wx packages from the master branch at https://github.com/HeinrichApfelmus/reactive-banana This should work with wx-0.90 (though some examples crash), but I can't give any guarantees whether the official 0.6 version that I'm going to release on hackage will have the exact same API. That said, I'm basically just waiting for Jeremy to release a small patch to wx on hackage that fixes some of these issues (for instance the strangely minimized text entries and the crashes). After that, I'm going to release reactive-banana-0.6.0.0 that depends on wx-0.90. Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com

A 28/04/2012, às 15:50, Heinrich Apfelmus escreveu:
Miguel Negrao wrote:
I had a try again at running the examples of reactive-banana-wx. I unpacked reactive-banana-wx-0.5.0.0. I have installed wx and wxcore version 0.13.1, that’s what I managed to install at some point (I think there were some issue with OSX Lion on previous versions). So I changed the cabal setup of reactive-banana-wx-0.5.0.0 to wx==0.13.1, wxcore==0.13.1 and then did 'cabal install -fbuildExamples’ and everything builds. Most of the examples run fine, although the resize of the window is completely hacky, all the widgets assume strange proportion and become almost unusable (http://img440.imageshack.us/img440/1149/capturadeecr20120428s14.png) . The asteroids app (which was the one I wanted to have look at) the window becomes just a couple pixels, so I can’t see anything (http://img33.imageshack.us/img33/1149/capturadeecr20120428s14.png). Is there a problem in using wx 0.13.1 ? Btw, wx 0.90 "Builds and runs cleanly on 64 bit platforms (particularly MacOS X Lion)”. Would reactive-banana-wx work with wx0.9.0 ?
Ah, it looks like your version of wx got linked with wxWidgets 2.9.3 instead of wxWidgets 2.8 . This introduces various issues, in particular the ones you ran into.
Ah, ok, I did that by mistake, must have installed the wrong version of wxWidgets.
If you just want to try a few examples with wxWidgets 2.9.3, you can install reactive-banana-0.6.0.0 and the corresponding -wx packages from the master branch at
https://github.com/HeinrichApfelmus/reactive-banana
This should work with wx-0.90 (though some examples crash), but I can't give any guarantees whether the official 0.6 version that I'm going to release on hackage will have the exact same API.
That said, I'm basically just waiting for Jeremy to release a small patch to wx on hackage that fixes some of these issues (for instance the strangely minimized text entries and the crashes). After that, I'm going to release reactive-banana-0.6.0.0 that depends on wx-0.90.
Since I have wxWidgets 2.9.3 installed already I might as well give it a try with reactive-banana-0.6. I installed wx-0.90 and wxcore-0.90 and reactive-banana-0.6.0 (from git) without issues. I couldn’t install reactive-banana-wx though, I get this error: Configuring MissingH-1.1.1.0... Warning: This package indirectly depends on multiple versions of the same package. This is highly likely to cause a compile failure. package regex-base-0.93.2 requires mtl-2.0.1.0 package parsec-3.1.1 requires mtl-2.0.1.0 package parsec-3.1.1 requires mtl-2.1 package hslogger-1.1.5 requires mtl-2.1 package MissingH-1.1.1.0 requires mtl-2.1 package MissingH-1.1.1.0 requires parsec-3.1.1 package network-2.3.0.5 requires parsec-3.1.1 package mtl-2.0.1.0 requires transformers-0.2.2.0 package mtl-2.1 requires transformers-0.3.0.0 Preprocessing library MissingH-1.1.1.0... Preprocessing executables for MissingH-1.1.1.0... Building MissingH-1.1.1.0... <command line>: cannot satisfy -package-id parsec-3.1.1-178bb186a8cbec1a8bf6b3192212c18e: parsec-3.1.1-178bb186a8cbec1a8bf6b3192212c18e is shadowed by package parsec-3.1.1-fb91ea6e6c1f9c50292782ec985e5f9a (use -v for more information) Updating documentation index /Users/miguelnegrao/Library/Haskell/doc/index.html cabal: Error: some packages failed to install: MissingH-1.1.1.0 failed during the building phase. The exception was: ExitFailure 1 cabal-macosx-0.2 depends on MissingH-1.1.1.0 which failed to install. reactive-banana-wx-0.6.0.0 depends on MissingH-1.1.1.0 which failed to install. Thanks ! Miguel Negrão ps: Does reactive-banana also have time functions like it is described in conal’s papers ? i.e. can I just animate something with a function like cos (t) or do I have to explicitly create timers myself ? ps2: Sorry yet again for mailing you personally... I just can’t seem to remember that this list operates via cc and not reply...

Miguel Negrao wrote:
Since I have wxWidgets 2.9.3 installed already I might as well give it a try with reactive-banana-0.6. I installed wx-0.90 and wxcore-0.90 and reactive-banana-0.6.0 (from git) without issues. I couldn’t install reactive-banana-wx though, I get this error:
Configuring MissingH-1.1.1.0... Warning: This package indirectly depends on multiple versions of the same package. This is highly likely to cause a compile failure. package regex-base-0.93.2 requires mtl-2.0.1.0 package parsec-3.1.1 requires mtl-2.0.1.0 package parsec-3.1.1 requires mtl-2.1 package hslogger-1.1.5 requires mtl-2.1 package MissingH-1.1.1.0 requires mtl-2.1 package MissingH-1.1.1.0 requires parsec-3.1.1 package network-2.3.0.5 requires parsec-3.1.1 package mtl-2.0.1.0 requires transformers-0.2.2.0 package mtl-2.1 requires transformers-0.3.0.0 Preprocessing library MissingH-1.1.1.0... Preprocessing executables for MissingH-1.1.1.0... Building MissingH-1.1.1.0... <command line>: cannot satisfy -package-id parsec-3.1.1-178bb186a8cbec1a8bf6b3192212c18e: parsec-3.1.1-178bb186a8cbec1a8bf6b3192212c18e is shadowed by package parsec-3.1.1-fb91ea6e6c1f9c50292782ec985e5f9a (use -v for more information) Updating documentation index /Users/miguelnegrao/Library/Haskell/doc/index.html cabal: Error: some packages failed to install: MissingH-1.1.1.0 failed during the building phase. The exception was: ExitFailure 1 cabal-macosx-0.2 depends on MissingH-1.1.1.0 which failed to install. reactive-banana-wx-0.6.0.0 depends on MissingH-1.1.1.0 which failed to install.
Fortunately, this time it's not my fault. :) You ran into a cabal problem with a package depending on multiple versions of the same package. The culprit seems to be regex-base . I suggest you try cabal install regex-base parsec-3.1.1 \ --reinstall --constraint='mtl == 2.1' to resolve this issue. Then try installing reactive-banana-wx again.
ps: Does reactive-banana also have time functions like it is described in conal’s papers ? i.e. can I just animate something with a function like cos (t) or do I have to explicitly create timers myself ?
No, you have to create timers yourself. It's not very difficult, though, you can just create a wxWidget and listen to its command event. Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com

A 01/05/2012, às 19:24, Heinrich Apfelmus escreveu:
Miguel Negrao wrote:
Since I have wxWidgets 2.9.3 installed already I might as well give it a try with reactive-banana-0.6. I installed wx-0.90 and wxcore-0.90 and reactive-banana-0.6.0 (from git) without issues. I couldn’t install reactive-banana-wx though, I get this error: Configuring MissingH-1.1.1.0... Warning: This package indirectly depends on multiple versions of the same package. This is highly likely to cause a compile failure. package regex-base-0.93.2 requires mtl-2.0.1.0 package parsec-3.1.1 requires mtl-2.0.1.0 package parsec-3.1.1 requires mtl-2.1 package hslogger-1.1.5 requires mtl-2.1 package MissingH-1.1.1.0 requires mtl-2.1 package MissingH-1.1.1.0 requires parsec-3.1.1 package network-2.3.0.5 requires parsec-3.1.1 package mtl-2.0.1.0 requires transformers-0.2.2.0 package mtl-2.1 requires transformers-0.3.0.0 Preprocessing library MissingH-1.1.1.0... Preprocessing executables for MissingH-1.1.1.0... Building MissingH-1.1.1.0... <command line>: cannot satisfy -package-id parsec-3.1.1-178bb186a8cbec1a8bf6b3192212c18e: parsec-3.1.1-178bb186a8cbec1a8bf6b3192212c18e is shadowed by package parsec-3.1.1-fb91ea6e6c1f9c50292782ec985e5f9a (use -v for more information) Updating documentation index /Users/miguelnegrao/Library/Haskell/doc/index.html cabal: Error: some packages failed to install: MissingH-1.1.1.0 failed during the building phase. The exception was: ExitFailure 1 cabal-macosx-0.2 depends on MissingH-1.1.1.0 which failed to install. reactive-banana-wx-0.6.0.0 depends on MissingH-1.1.1.0 which failed to install.
Fortunately, this time it's not my fault. :)
You ran into a cabal problem with a package depending on multiple versions of the same package. The culprit seems to be regex-base . I suggest you try
cabal install regex-base parsec-3.1.1 \ --reinstall --constraint='mtl == 2.1'
to resolve this issue.
That installs regex-base-0.93.2 with no errors.
Then try installing reactive-banana-wx again.
But then I get the same error installing reactive-banana-wx.
ps: Does reactive-banana also have time functions like it is described in conal’s papers ? i.e. can I just animate something with a function like cos (t) or do I have to explicitly create timers myself ?
No, you have to create timers yourself. It's not very difficult, though, you can just create a wxWidget and listen to its command event.
Is any generality lost because of this or are the approaches equivalent ? best, Miguel Negrão

A 01/05/2012, às 21:19, Miguel Negrao escreveu:
A 01/05/2012, às 19:24, Heinrich Apfelmus escreveu:
Miguel Negrao wrote:
Since I have wxWidgets 2.9.3 installed already I might as well give it a try with reactive-banana-0.6. I installed wx-0.90 and wxcore-0.90 and reactive-banana-0.6.0 (from git) without issues. I couldn’t install reactive-banana-wx though, I get this error: Configuring MissingH-1.1.1.0... Warning: This package indirectly depends on multiple versions of the same package. This is highly likely to cause a compile failure. package regex-base-0.93.2 requires mtl-2.0.1.0 package parsec-3.1.1 requires mtl-2.0.1.0 package parsec-3.1.1 requires mtl-2.1 package hslogger-1.1.5 requires mtl-2.1 package MissingH-1.1.1.0 requires mtl-2.1 package MissingH-1.1.1.0 requires parsec-3.1.1 package network-2.3.0.5 requires parsec-3.1.1 package mtl-2.0.1.0 requires transformers-0.2.2.0 package mtl-2.1 requires transformers-0.3.0.0 Preprocessing library MissingH-1.1.1.0... Preprocessing executables for MissingH-1.1.1.0... Building MissingH-1.1.1.0... <command line>: cannot satisfy -package-id parsec-3.1.1-178bb186a8cbec1a8bf6b3192212c18e: parsec-3.1.1-178bb186a8cbec1a8bf6b3192212c18e is shadowed by package parsec-3.1.1-fb91ea6e6c1f9c50292782ec985e5f9a (use -v for more information) Updating documentation index /Users/miguelnegrao/Library/Haskell/doc/index.html cabal: Error: some packages failed to install: MissingH-1.1.1.0 failed during the building phase. The exception was: ExitFailure 1 cabal-macosx-0.2 depends on MissingH-1.1.1.0 which failed to install. reactive-banana-wx-0.6.0.0 depends on MissingH-1.1.1.0 which failed to install.
Fortunately, this time it's not my fault. :)
You ran into a cabal problem with a package depending on multiple versions of the same package. The culprit seems to be regex-base . I suggest you try
cabal install regex-base parsec-3.1.1 \ --reinstall --constraint='mtl == 2.1'
to resolve this issue.
That installs regex-base-0.93.2 with no errors.
Then try installing reactive-banana-wx again.
But then I get the same error installing reactive-banana-wx.
cabal install regex-base parsec-3.1.1 MissingH --reinstall --constraint='mtl == 2.1’ With this command it installs correctly, I can now run all the examples. All seem to work fine except CRUD that crashed at some point. I will now start exploring. thanks, Miguel

Miguel Negrao wrote:
cabal install regex-base parsec-3.1.1 MissingH --reinstall --constraint='mtl == 2.1’
With this command it installs correctly, I can now run all the examples. All seem to work fine except CRUD that crashed at some point.
Great! By the way, the crash is fixed in the development version of wxHaskell https://github.com/jodonoghue/wxHaskell
No, you have to create timers yourself. It's not very difficult, though, you can just create a wxWidget and listen to its command event.
Is any generality lost because of this or are the approaches equivalent ?
Once you have a timer, you can make a behavior time :: Behavior t Time that indicates the current time and thus allows you to write functions that depend on the current clock time, just like in Conal's papers. In other words, the approaches are largely equivalent. The thing is just that different GUI or audio frameworks tend to have different implementations of timers and reactive-banana can't decide which one is more appropriate. For instance, Henning Thielemann uses ALSA-timers in his reactive-balsa package http://hackage.haskell.org/package/reactive-balsa-0.0 At some point, I intend to offer some common time-related functionality (for example as in the Wave.hs example) for different backends. Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com

Hi,
Is any generality lost because of this or are the approaches equivalent ?
Once you have a timer, you can make a behavior
time :: Behavior t Time
that indicates the current time and thus allows you to write functions that depend on the current clock time, just like in Conal's papers.
In other words, the approaches are largely equivalent.
The thing is just that different GUI or audio frameworks tend to have different implementations of timers and reactive-banana can't decide which one is more appropriate. For instance, Henning Thielemann uses ALSA-timers in his reactive-balsa package
http://hackage.haskell.org/package/reactive-balsa-0.0
At some point, I intend to offer some common time-related functionality (for example as in the Wave.hs example) for different backends.
Ok, I see, yes make sense. One other question, is it possible in reactive-banana to define “recursive” event streams. For instance consider a stream which receives numbers between 0.0 and 1.0. If the last outputted value was between 0.8 an 1.0 then output 1-x otherwise output x. After that it only leta numbers through if they are between 0.0 and 0.2 or between 0.8 and 1.0. This looks like: | x V --------------------------- | y > 0.8 |<--------------y----------------| | | | -------------------------- | | | | | yes | no | V V | 1-x x | | / | V / | -------------- | | | | | V | ---------------------------------------------------- | | select values between 0.0 and 0.2 | | | and 0 8 and 1.0 | | | || | ---------------------------------------------------- | | | |------------------------------------------------------------ | y | V best, Miguel Negrão

Miguel Negrao wrote:
One other question, is it possible in reactive-banana to define “recursive” event streams. For instance consider a stream which receives numbers between 0.0 and 1.0. If the last outputted value was between 0.8 an 1.0 then output 1-x otherwise output x. After that it only leta numbers through if they are between 0.0 and 0.2 or between 0.8 and 1.0.
The standard way to do recursion in reactive-banana is to use multiple recursion between a Behavior and an Event . See also http://stackoverflow.com/a/7852344/403805 Note that the specification you gave does not require recursion, though. Here an implementation of your example. import Reactive.Banana example :: Event t Double -> Event t Double example e = filterJust e2 where e2 = f <$> bIsFirst <@> e bIsFirst = stepper True $ False <$ e between x a b = a < x && x < b f True x | between x 0.8 1.0 = Just $ 1 - x | otherwise = Just $ x f False x | between x 0.8 1.0 = Just $ x | between x 0.0 0.2 = Just $ x | otherwise = Nothing Here an example output GHCi> interpretModel example [[0.9],[0.3],[0.4]] [[9.999999999999998e-2],[],[]] Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com

A 05/05/2012, às 08:40, Heinrich Apfelmus escreveu:
Miguel Negrao wrote:
One other question, is it possible in reactive-banana to define “recursive” event streams. For instance consider a stream which receives numbers between 0.0 and 1.0. If the last outputted value was between 0.8 an 1.0 then output 1-x otherwise output x. After that it only leta numbers through if they are between 0.0 and 0.2 or between 0.8 and 1.0.
The standard way to do recursion in reactive-banana is to use multiple recursion between a Behavior and an Event . See also
ok, I will study that.
Note that the specification you gave does not require recursion, though. Here an implementation of your example.
import Reactive.Banana
example :: Event t Double -> Event t Double example e = filterJust e2 where e2 = f <$> bIsFirst <@> e
bIsFirst = stepper True $ False <$ e
between x a b = a < x && x < b
f True x | between x 0.8 1.0 = Just $ 1 - x | otherwise = Just $ x f False x | between x 0.8 1.0 = Just $ x | between x 0.0 0.2 = Just $ x | otherwise = Nothing
Here an example output
GHCi> interpretModel example [[0.9],[0.3],[0.4]] [[9.999999999999998e-2],[],[]]
Hum, that’s not exactly what I wanted. So if it’s the first event just let it through, and then filter it. If it’s not the first event, then do the inversion (1-x) or not depending on the last outputted value, and then filter it. An input of [[0.9],[0.5],[0.1],[0.9],[0.9]] should produce [[0.9],[],[0.9],[0.1],[0.9]] The following code is not correct but it’s closer to what I described: module Main where import Reactive.Banana main :: IO() main = do list <- interpretModel example [[0.9],[0.3],[0.4],[0.15],[0.87]] putStrLn $ show list example :: Event t Double -> Event t Double example e = filterede2 where filterede2 = filterE (\x->between x 0.0 0.2 && between x 0.8 1.0) e2 e2 = f <$> bIsFirst <@> e <@> e2 bIsFirst = stepper True $ False <$ e between x a b = a < x && x < b f True x y = x f False x y | between y 0.8 1.0 = 1 - x | otherwise = x best, Miguel

Miguel Negrao wrote:
Hum, that’s not exactly what I wanted. So if it’s the first event just let it through, and then filter it. If it’s not the first event, then do the inversion (1-x) or not depending on the last outputted value, and then filter it.
An input of [[0.9],[0.5],[0.1],[0.9],[0.9]] should produce [[0.9],[],[0.9],[0.1],[0.9]]
The following code is not correct but it’s closer to what I described:
Ah, ok, then I don't understand your specification. Could you give a specification in terms of a simple list transformation example :: [Double] -> [Double] ? All list functions are allowed, we can then transform it into a style that uses only the combinators available in reactive-banana. Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com

A 06/05/2012, às 14:31, Heinrich Apfelmus escreveu:
Ah, ok, then I don't understand your specification.
Could you give a specification in terms of a simple list transformation
example :: [Double] -> [Double]
? All list functions are allowed, we can then transform it into a style that uses only the combinators available in reactive-banana.
Ok, this should demonstrate an example of what I mean: module Main where main :: IO() main = print $ test [0.9,0.1,0.2,0.8] --should output [0.9,0.1,0.8,0.8] test :: [Double]->[Double] test (x:xs) = x : test1 xs x test [] = [] test1:: [Double]->Double->[Double] test1 (x:xs) lastValue = let y = if lastValue>=0.8 then x else 1.0-x in if (y<=0.2) || (y>=0.8) then y : test1 xs y else test1 xs lastValue test1 [] _ = [] best, Miguel Negrão

Miguel Negrao wrote:
A 06/05/2012, às 14:31, Heinrich Apfelmus escreveu:
Ah, ok, then I don't understand your specification.
Could you give a specification in terms of a simple list transformation
example :: [Double] -> [Double]
? All list functions are allowed, we can then transform it into a style that uses only the combinators available in reactive-banana.
Ok, this should demonstrate an example of what I mean:
module Main where
main :: IO() main = print $ test [0.9,0.1,0.2,0.8] --should output [0.9,0.1,0.8,0.8]
test :: [Double]->[Double] test (x:xs) = x : test1 xs x test [] = []
test1:: [Double]->Double->[Double] test1 (x:xs) lastValue = let y = if lastValue>=0.8 then x else 1.0-x in if (y<=0.2) || (y>=0.8) then y : test1 xs y else test1 xs lastValue test1 [] _ = []
You can reformulate this function in terms of the mapAccum combinators from Data.List. Once you have done this, you can easily adapt it to the mapAccum combinator from reactive-banana. test :: Event t Double -> Event t Double test e = filterJust $ fst $ mapAccum Nothing $ next <$> e where next x Nothing = (Just x, Just x) next x (Just lastValue) = let y = if lastValue>=0.8 then x else 1.0-x in if (y<=0.2) || (y>=0.8) then (Just y , Just y) else (Nothing, Just lastValue) Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com

A 07/05/2012, às 13:12, Heinrich Apfelmus escreveu:
Miguel Negrao wrote:
Ah, ok, then I don't understand your specification.
Could you give a specification in terms of a simple list transformation
example :: [Double] -> [Double]
? All list functions are allowed, we can then transform it into a style that uses only the combinators available in reactive-banana. Ok, this should demonstrate an example of what I mean: module Main where
A 06/05/2012, às 14:31, Heinrich Apfelmus escreveu: main :: IO() main = print $ test [0.9,0.1,0.2,0.8] --should output [0.9,0.1,0.8,0.8] test :: [Double]->[Double] test (x:xs) = x : test1 xs x test [] = [] test1:: [Double]->Double->[Double] test1 (x:xs) lastValue = let y = if lastValue>=0.8 then x else 1.0-x in if (y<=0.2) || (y>=0.8) then y : test1 xs y else test1 xs lastValue test1 [] _ = []
You can reformulate this function in terms of the mapAccum combinators from Data.List. Once you have done this, you can easily adapt it to the mapAccum combinator from reactive-banana.
test :: Event t Double -> Event t Double test e = filterJust $ fst $ mapAccum Nothing $ next <$> e where next x Nothing = (Just x, Just x) next x (Just lastValue) = let y = if lastValue>=0.8 then x else 1.0-x in if (y<=0.2) || (y>=0.8) then (Just y , Just y) else (Nothing, Just lastValue)
Thanks, mapAccum is what I was missing. best, Miguel

A 05/05/2012, às 15:26, Miguel Negrao escreveu:
Hum, that’s not exactly what I wanted. So if it’s the first event just let it through, and then filter it. If it’s not the first event, then do the inversion (1-x) or not depending on the last outputted value, and then filter it. An input of [[0.9],[0.5],[0.1],[0.9],[0.9]] should produce [[0.9],[],[0.9],[0.1],[0.9]]
The following code is not correct but it’s closer to what I described:
module Main where
import Reactive.Banana
main :: IO() main = do list <- interpretModel example [[0.9],[0.3],[0.4],[0.15],[0.87]] putStrLn $ show list
example :: Event t Double -> Event t Double example e = filterede2 where filterede2 = filterE (\x->between x 0.0 0.2 && between x 0.8 1.0) e2 e2 = f <$> bIsFirst <@> e <@> e2
bIsFirst = stepper True $ False <$ e
between x a b = a < x && x < b
f True x y = x f False x y | between y 0.8 1.0 = 1 - x | otherwise = x
Actually I just spotted that the filtering should not be done after the “recursive” part. It should be something more like:
example e = e2 where e2 = filterE (\x->between x 0.0 0.2 && between x 0.8 1.0) (f <$> bIsFirst <@> e <@> e2)
best, Miguel Negrão
participants (3)
-
Brent Yorgey
-
Heinrich Apfelmus
-
Miguel Negrao