Skip to content

Commit

Permalink
Merge branch 'develop' into jd-fancy-throttle
Browse files Browse the repository at this point in the history
  • Loading branch information
luigy committed Jan 16, 2019
2 parents 2e2e19d + fc68de9 commit 53698df
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 29 deletions.
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

17 changes: 17 additions & 0 deletions Quickref.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,20 @@ Th typeclasses and their associated annotations include:
[P,T] delay :: NominalDiffTime -> Event t a -> m (Event t a)
```

## Networks

```haskell
-- Functions from Reflex.Network used to deal with Dynamics/Events carrying (m a)

-- Given a Dynamic of network-creating actions, create a network that is recreated whenever the Dynamic updates.
-- The returned Event of network results occurs when the Dynamic does. Note: Often, the type a is an Event,
-- in which case the return value is an Event-of-Events that would typically be flattened (via switchHold).
[P,A] networkView :: Dynamic (m a) -> m (Event a)

-- Given an initial network and an Event of network-creating actions, create a network that is recreated whenever the
-- Event fires. The returned Dynamic of network results occurs when the Event does. Note: Often, the type a is an
-- Event, in which case the return value is a Dynamic-of-Events that would typically be flattened.
[H,A] networkHold :: m a -> Event (m a) -> m (Dynamic a)

-- Render a placeholder network to be shown while another network is not yet done building
[P,A] untilReady :: m a -> m b -> m (a, Event b)
29 changes: 29 additions & 0 deletions hydra.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"enabled": 1,
"hidden": true,
"description": "Jobsets",
"nixexprinput": "src",
"nixexprpath": "jobsets.nix",
"checkinterval": 300,
"schedulingshares": 100,
"enableemail": false,
"emailoverride": "",
"keepnr": 10,
"inputs": {
"src": {
"type": "git",
"value": "https://github.com/reflex-frp/reflex.git develop",
"emailresponsible": false
},
"nixpkgs": {
"type": "git",
"value": "https://github.com/NixOS/nixpkgs-channels nixos-unstable",
"emailresponsible": false
},
"prs": {
"type": "githubpulls",
"value": "reflex-frp reflex",
"emailresponsible": false
}
}
}
70 changes: 70 additions & 0 deletions jobsets.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{ prs }:

let
pkgs = (import ./reflex-platform.nix {}).nixpkgs;
mkFetchGithub = value: {
inherit value;
type = "git";
emailresponsible = false;
};
in
with pkgs.lib;
let
defaults = jobs: {
inherit (jobs) description;
enabled = 1;
hidden = false;
keepnr = 10;
schedulingshares = 100;
checkinterval = 120;
enableemail = false;
emailoverride = "";
nixexprinput = "reflex";
nixexprpath = "release.nix";
inputs = jobs.inputs // {
nixpkgs = {
type = "git";
value = "https://github.com/NixOS/nixpkgs-channels nixos-unstable";
emailresponsible = false;
};
config = {
type = "nix";
value = "{ android_sdk.accept_license = true; }";
emailresponsible = false;
};
};
};
branchJobset = branch: defaults {
description = "reflex-${branch}";
inputs = {
reflex = {
value = "https://github.com/reflex-frp/reflex ${branch}";
type = "git";
emailresponsible = false;
};
};
};
makePr = num: info: {
name = "reflex-pr-${num}";
value = defaults {
description = "#${num}: ${info.title}";
inputs = {
reflex = {
#NOTE: This should really use "pull/${num}/merge"; however, GitHub's
#status checks only operate on PR heads. This creates a race
#condition, which can currently only be solved by requiring PRs to be
#up to date before they're merged. See
#https://github.com/isaacs/github/issues/1002
value = "https://github.com/reflex-frp/reflex pull/${num}/head";
type = "git";
emailresponsible = false;
};
};
};
};
processedPrs = mapAttrs' makePr (builtins.fromJSON (builtins.readFile prs));
jobsetsAttrs = processedPrs //
genAttrs ["develop"] branchJobset;
in {
jobsets = pkgs.writeText "spec.json" (builtins.toJSON jobsetsAttrs);
}
8 changes: 8 additions & 0 deletions reflex-platform.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let
reflex-platform-src = (import <nixpkgs> {}).fetchFromGitHub {
owner = "reflex-frp";
repo = "reflex-platform";
rev = "384cd850f3adf1d404bced2424b5f6efb0f415f2";
sha256 = "1ws77prqx8khmp8j6br1ij4k2v4dlgv170r9fmg0p1jivfbn8y9d";
};
in import reflex-platform-src
9 changes: 9 additions & 0 deletions release.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ rp ? import ./reflex-platform.nix {}
}:
let
inherit (rp.nixpkgs) lib;
compilers = ["ghc8_4" "ghc8_0" "ghcjs8_4" "ghcjs8_0"];
in lib.genAttrs compilers (ghc: {
reflex-useTemplateHaskell = rp.${ghc}.callPackage ./. { useTemplateHaskell = true; };
reflex = rp.${ghc}.callPackage ./. { useTemplateHaskell = false; };
})
2 changes: 0 additions & 2 deletions src/Reflex/BehaviorWriter/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ Description: Implementation of MonadBehaviorWriter
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE StandaloneDeriving #-}
Expand Down
4 changes: 2 additions & 2 deletions src/Reflex/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -926,8 +926,8 @@ instance Reflex t => Align (Event t) where
gate :: Reflex t => Behavior t Bool -> Event t a -> Event t a
gate = attachWithMaybe $ \allow a -> if allow then Just a else Nothing

-- | Create a new behavior given a starting behavior and switch to a the behvior
-- carried by the event when it fires.
-- | Create a new behavior given a starting behavior and switch to the behavior
-- carried by the event when it fires.
switcher :: (Reflex t, MonadHold t m)
=> Behavior t a -> Event t (Behavior t a) -> m (Behavior t a)
switcher b eb = pull . (sample <=< sample) <$> hold b eb
Expand Down
2 changes: 1 addition & 1 deletion src/Reflex/EventWriter/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import Unsafe.Coerce

{-# DEPRECATED TellId "Do not construct this directly; use tellId instead" #-}
newtype TellId w x
= TellId Int -- ^ WARNING: Do not construct this directly; use 'TellId' instead
= TellId Int -- ^ WARNING: Do not construct this directly; use 'tellId' instead
deriving (Show, Eq, Ord, Enum)

tellId :: Int -> TellId w w
Expand Down
5 changes: 5 additions & 0 deletions src/Reflex/Query/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module Reflex.Query.Base
import Control.Applicative (liftA2)
import Control.Monad.Exception
import Control.Monad.Fix
import Control.Monad.Primitive
import Control.Monad.Reader
import Control.Monad.Ref
import Control.Monad.State.Strict
Expand Down Expand Up @@ -244,6 +245,10 @@ instance (Reflex t, MonadFix m, Group q, Additive q, Query q, MonadHold t m, Adj
instance MonadTrans (QueryT t q) where
lift = QueryT . lift . lift . lift

instance PrimMonad m => PrimMonad (QueryT t q m) where
type PrimState (QueryT t q m) = PrimState m
primitive = lift . primitive

instance PostBuild t m => PostBuild t (QueryT t q m) where
getPostBuild = lift getPostBuild

Expand Down
6 changes: 5 additions & 1 deletion src/Reflex/Spider/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2307,9 +2307,13 @@ newJoinDyn d =
in Reflex.Spider.Internal.unsafeBuildDynamic readV0 v'

instance HasSpiderTimeline x => Functor (Reflex.Class.Dynamic (SpiderTimeline x)) where
fmap f = SpiderDynamic . newMapDyn f . unSpiderDynamic
fmap = mapDynamicSpider
x <$ d = R.unsafeBuildDynamic (return x) $ x <$ R.updated d

mapDynamicSpider :: HasSpiderTimeline x => (a -> b) -> Reflex.Class.Dynamic (SpiderTimeline x) a -> Reflex.Class.Dynamic (SpiderTimeline x) b
mapDynamicSpider f = SpiderDynamic . newMapDyn f . unSpiderDynamic
{-# INLINE [1] mapDynamicSpider #-}

instance HasSpiderTimeline x => Applicative (Reflex.Class.Dynamic (SpiderTimeline x)) where
pure = SpiderDynamic . dynamicConst
#if MIN_VERSION_base(4,10,0)
Expand Down
7 changes: 6 additions & 1 deletion test/QueryT.hs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}

import Control.Lens
import Control.Monad.Fix
import Data.Align
import Data.AppendMap () -- for the Align instance
import qualified Data.AppendMap as AMap
import Data.Functor.Misc
import Data.Map (Map)
Expand All @@ -36,6 +37,10 @@ instance (Ord k, Query a, Eq (QueryResult a), Align (MonoidalMap k)) => Query (S
newtype Selector k a = Selector { unSelector :: MonoidalMap k a }
deriving (Show, Read, Eq, Ord, Functor)

#if !(MIN_VERSION_monoidal_containers(0,4,1))
deriving instance Ord k => Align (MonoidalMap k)
#endif

instance (Ord k, Eq a, Monoid a, Align (MonoidalMap k)) => Semigroup (Selector k a) where
(Selector a) <> (Selector b) = Selector $ fmapMaybe id $ f a b
where
Expand Down
8 changes: 4 additions & 4 deletions test/Reflex/Plan/Pure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ instance TestPlan (Pure Int) PurePlan where
runPure :: PurePlan a -> (a, IntSet)
runPure (PurePlan p) = runStateT p mempty $ 0

relavantTimes :: IntSet -> IntSet
relavantTimes occs = IntSet.fromList [0..l + 1]
relevantTimes :: IntSet -> IntSet
relevantTimes occs = IntSet.fromList [0..l + 1]
where l = fromMaybe 0 (fst <$> IntSet.maxView occs)

testBehavior :: (Behavior (Pure Int) a, IntSet) -> IntMap a
testBehavior (b, occs) = IntMap.fromSet (sample b) (relavantTimes occs)
testBehavior (b, occs) = IntMap.fromSet (sample b) (relevantTimes occs)

testEvent :: (Event (Pure Int) a, IntSet) -> IntMap (Maybe a)
testEvent (Event readEvent, occs) = IntMap.fromSet readEvent (relavantTimes occs)
testEvent (Event readEvent, occs) = IntMap.fromSet readEvent (relevantTimes occs)



Expand Down
4 changes: 2 additions & 2 deletions test/Reflex/TestPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import Reflex.Class
import Prelude

class (Reflex t, MonadHold t m, MonadFix m) => TestPlan t m where
-- | Speicify a plan of an input Event firing
-- Occurances must be in the future (i.e. Time > 0)
-- | Specify a plan of an input Event firing
-- Occurrences must be in the future (i.e. Time > 0)
-- Initial specification is

plan :: [(Word, a)] -> m (Event t a)
Expand Down

0 comments on commit 53698df

Please sign in to comment.