turion / rhine

Haskell Functional Reactive Programming framework with type-level clocks
http://hackage.haskell.org/package/rhine
123 stars 21 forks source link

Add LIFO buffers #34

Closed turion closed 6 years ago

turion commented 6 years ago

All FIFO buffers can also exist in a LIFO variant.

alexpeits commented 6 years ago

I'd like to have a go at this if it's ok! Beginner towards intermediate, however this library has several new concepts that I'd like to look into.

turion commented 6 years ago

@alexpeits By any means give it a go! Just create a pull request, and we'll work on it in until we can merge it :)

turion commented 6 years ago

@alexpeits it's probably easiest if you just copy the module FRP.Rhine.ResamplingBuffer.FIFO and then reverse the order in which elements are taken from the buffer.

alexpeits commented 6 years ago

@turion Any examples on how to use the resampling buffers would be welcome to test my additions. In any case, the implementation is what you mentioned. Elements are still pushed to the left of the Seq and popped with viewl, which, from my understanding, yields the same results and performance as pushing to the right end with |> and popping with viewr.

turion commented 6 years ago

Great! You can test the buffer by creating a simple interactive example like this:

{-# LANGUAGE DataKinds #-}

import FRP.Rhine
import FRP.Rhine.Clock.Realtime.Millisecond
import FRP.Rhine.Clock.Realtime.Stdin
import FRP.Rhine.ResamplingBuffer.LIFO
import FRP.Rhine.Schedule.Concurrently

main = flow $ count @@ (waitClock :: Millisecond 500) >-- lifo -@- concurrently --> arrMSync print @@ StdinClock

Every half second, a number is put onto the buffer, and on every return press, a number is popped from it and output.

You can write an automatable test, you can use pure clocks like those from #40.

Thanks for your contribution, you're welcome to write more ;)