Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrowLoop is more lazy #33

Merged
merged 1 commit into from
Sep 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.stack-work
stack.yaml.lock
dist
cabal-dev
*.sw[a-z]
Expand Down
25 changes: 20 additions & 5 deletions src/Control/Varying/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ import Prelude hiding (id, (.))
-- | A continuously varying value, with effects.
-- It's a kind of <https://en.wikipedia.org/wiki/Mealy_machine Mealy machine>
-- (an automaton).
newtype VarT m a b = VarT { runVarT :: a -> m (b, VarT m a b) }
-- ^ Run a @VarT@ computation with an input value of
-- type 'a', yielding a step - a value of type 'b'
-- and a new computation for yielding the next step.
newtype VarT m a b
= VarT
{ runVarT :: a -> m (b, VarT m a b) }
-- ^ Run a @VarT@ computation with an input value of
-- type 'a', yielding a step - a value of type 'b'
-- and a new computation for yielding the next step.


-- | A var parameterized with Identity that takes input of type @a@
Expand Down Expand Up @@ -175,8 +177,21 @@ instance Monad m => ArrowApply (VarT m) where
(c, _) <- runVarT v b
return (c, app)

-- | Inputs can depend on outputs as long as no time-travel is required.
--
-- This isn't the best example but it does make a good test case:
-- >>> :{
-- let
-- testVar :: VarT IO Double (Maybe Double)
-- testVar = proc val -> do
-- rec _ <- returnA -< 0.5
-- returnA -< Just 5.0
-- in
-- testVarOver testVar [5.0]
-- >>> :}
-- Just 5.0
instance MonadFix m => ArrowLoop (VarT m) where
loop vmbdcd = VarT $ \b -> fmap fst $ mfix $ \(_, d) -> do
loop vmbdcd = VarT $ \b -> fmap fst $ mfix $ \(~(_, d)) -> do
((c1, d1), vmbdcd1) <- runVarT vmbdcd (b, d)
return ((c1, loop vmbdcd1), d1)

Expand Down
67 changes: 43 additions & 24 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# http://docs.haskellstack.org/en/stable/yaml_configuration/
# https://docs.haskellstack.org/en/stable/yaml_configuration/

# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
Expand All @@ -11,37 +11,56 @@
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
# resolver: ghcjs-0.1.0_ghc-7.10.2
# resolver:
# name: custom-snapshot
# location: "./custom-snapshot.yaml"
resolver: lts-8.16
#
# The location of a snapshot can be provided as a file or url. Stack assumes
# a snapshot provided as a file might change, whereas a url resource does not.
#
# resolver: ./custom-snapshot.yaml
# resolver: https://example.com/snapshots/2018-01-01.yaml
resolver: lts-14.5

# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# - location:
# git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# extra-dep: true
# subdirs:
# - auto-update
# - wai
#
# A package marked 'extra-dep: true' will only be built if demanded by a
# non-dependency (i.e. a user package), and its test suites and benchmarks
# will not be run. This is useful for tweaking upstream packages.
# subdirs:
# - auto-update
# - wai
packages:
- '.'
# Dependency packages to be pulled from upstream that are not in the resolver
# (e.g., acme-missiles-0.3)
extra-deps: []
- .
# Dependency packages to be pulled from upstream that are not in the resolver.
# These entries can reference officially published versions as well as
# forks / in-progress versions pinned to a git hash. For example:
#
# extra-deps:
# - acme-missiles-0.3
# - git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
#
# extra-deps: []

flags: {}
# Override default flag values for local packages and extra-deps
# flags: {}

# Extra package databases containing global packages
extra-package-dbs: []
# extra-package-dbs: []

# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=2.1"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor