Last active
November 18, 2020 07:55
-
-
Save johannes-riecken/8882107a4d8f409fc59b8e2bfdaa4751 to your computer and use it in GitHub Desktop.
Integral using causal commutative arrows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Arrow | |
import Control.Arrow.Operations | |
import Control.Arrow.Transformer.All | |
import Data.Stream | |
frequency :: Int | |
frequency = 1024 | |
exp :: StreamArrow (->) () Double | |
exp = fixA (integral >>> arr (+1)) | |
fixA :: ArrowLoop a => a b b -> a () b | |
fixA f = loop (second f >>> arr (\((), y) -> (y, y))) | |
integral :: ArrowCircuit a => a Double Double | |
integral = loop (arr (\(v, i) -> i + dt * v) >>> delay 0 >>> arr diag) | |
diag :: a -> (a, a) | |
diag x = (x, x) | |
units = Cons () units | |
dt :: Double | |
dt = recip $ fromIntegral frequency | |
main :: IO () | |
main = print $ case (fixA (integral >>> arr (+1))) of StreamArrow x -> x units Data.Stream.!! frequency |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment