Skip to content

Commit 37851f1

Browse files
committed
Add MonadCatch, MonadThrow, MonadMask instances
1 parent bb55a2f commit 37851f1

17 files changed

+75
-18
lines changed

ChangeLog.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
* Change `inputInFocusedRegion` to filter mouse scroll wheel input based on if the region under than the mouse rather than using mouse drag tracking
6+
* Add MonadCatch, MonadThrow, and MonadMask instances (relies on reflex-0.9.2.0 or greater)
67

78
## 0.5.0.0
89

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

dep/reflex/default.nix

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# DO NOT HAND-EDIT THIS FILE
2+
import (import ./thunk.nix)

dep/reflex/github.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"owner": "reflex-frp",
3+
"repo": "reflex",
4+
"branch": "aa/monadmask",
5+
"private": false,
6+
"rev": "535978b825a3055e22d04b043657bb18786e59ba",
7+
"sha256": "03h5n2jzxmic779d334ini7bgy4xmy59j9iyd5pdprkpqqa930nh"
8+
}

dep/reflex/thunk.nix

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# DO NOT HAND-EDIT THIS FILE
2+
let fetch = { private ? false, fetchSubmodules ? false, owner, repo, rev, sha256, ... }:
3+
if !fetchSubmodules && !private then builtins.fetchTarball {
4+
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; inherit sha256;
5+
} else (import (builtins.fetchTarball {
6+
url = "https://github.com/NixOS/nixpkgs/archive/3aad50c30c826430b0270fcf8264c8c41b005403.tar.gz";
7+
sha256 = "0xwqsf08sywd23x0xvw4c4ghq0l28w2ki22h0bdn766i16z9q2gr";
8+
}) {}).fetchFromGitHub {
9+
inherit owner repo rev sha256 fetchSubmodules private;
10+
};
11+
json = builtins.fromJSON (builtins.readFile ./github.json);
12+
in fetch json

reflex-vty.cabal

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,15 @@ library
4848
stm >= 2.4 && < 2.6,
4949
data-default >= 0.7.1 && < 0.8,
5050
dependent-map >= 0.4 && < 0.5,
51+
exceptions >= 0.10 && < 0.11,
5152
text >= 1.2.3 && < 2.1,
5253
dependent-sum >= 0.7 && < 0.8,
5354
exception-transformers >= 0.4.0 && < 0.5,
5455
mmorph >= 1.1 && < 1.3,
5556
ordered-containers >= 0.2.2 && < 0.3,
5657
primitive >= 0.6.3 && < 0.8,
5758
ref-tf >= 0.4.0 && < 0.6,
58-
reflex >= 0.8 && < 1,
59+
reflex >= 0.9.2 && < 1,
5960
time >= 1.8.0 && < 1.13,
6061
vty >= 5.28 && < 5.39
6162
hs-source-dirs: src

release.nix

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
{ reflex-platform ? import ./reflex-platform
1+
{ reflex-platform ? import ./dep/reflex-platform
22
}:
33
let
4-
pkgs = (reflex-platform {}).nixpkgs;
4+
rp = reflex-platform {};
5+
pkgs = rp.nixpkgs;
56
supportedSystems = [ "x86_64-linux" "x86_64-darwin" ];
67
inherit (pkgs) lib;
78
haskellLib = pkgs.haskell.lib;
@@ -11,13 +12,14 @@ let
1112
ver = "5.38";
1213
sha256 = "0kcd3ln9xmc62ka0i7habzvjjar8z63mlvl15rdhf8hqmda0b7r7";
1314
} {};
15+
reflex = self.callCabal2nix "reflex" (rp.hackGet ./dep/reflex) {};
1416
};
1517
ghcs = lib.genAttrs supportedSystems (system: let
1618
rp = reflex-platform { inherit system; __useNewerCompiler = true; };
1719
rpGhc = rp.ghc.override {
1820
overrides = commonOverrides;
1921
};
20-
nixGhc945 = (import ./nixpkgs { inherit system; }).haskell.packages.ghc945.override {
22+
nixGhc945 = (import ./dep/nixpkgs { inherit system; }).haskell.packages.ghc945.override {
2123
overrides = self: super: commonOverrides self super // {
2224
hlint = self.callHackageDirect {
2325
pkg = "hlint";
@@ -40,7 +42,7 @@ let
4042
} {};
4143
};
4244
};
43-
nixGhc961 = (import ./nixpkgs { inherit system; }).haskell.packages.ghc961.override {
45+
nixGhc961 = (import ./dep/nixpkgs { inherit system; }).haskell.packages.ghc961.override {
4446
overrides = self: super: {
4547
patch = self.callHackageDirect {
4648
pkg = "patch";

shell.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# or nixpkgs (which provides ghc943)
33
{ compiler ? "ghc810" # or "ghc943"
44
}:
5-
let pkgs = (import ./reflex-platform { }).nixpkgs;
5+
let pkgs = (import ./dep/reflex-platform { }).nixpkgs;
66
in
77
pkgs.mkShell {
88
name = "shell-${compiler}";

src/Control/Monad/NodeId.hs

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Control.Monad.NodeId
1010
, runNodeIdT
1111
) where
1212

13+
import Control.Monad.Catch (MonadCatch, MonadThrow, MonadMask)
1314
import Control.Monad.Morph
1415
import Control.Monad.Fix
1516
import Control.Monad.Reader
@@ -49,6 +50,9 @@ newtype NodeIdT m a = NodeIdT { unNodeIdT :: ReaderT (IORef NodeId) m a }
4950
, PerformEvent t
5051
, PostBuild t
5152
, TriggerEvent t
53+
, MonadCatch
54+
, MonadThrow
55+
, MonadMask
5256
)
5357

5458
instance MonadNodeId m => MonadNodeId (ReaderT x m)

src/Reflex/Vty/Host.hs

+16-12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Control.Concurrent (forkIO, killThread)
1616
import Control.Concurrent.Chan (newChan, readChan, writeChan)
1717
import Control.Exception (onException)
1818
import Control.Monad (forM, forM_, forever)
19+
import Control.Monad.Catch (MonadCatch, MonadThrow, MonadMask)
1920
import Control.Monad.Fix (MonadFix, fix)
2021
import Control.Monad.IO.Class (liftIO, MonadIO)
2122
import Control.Monad.Identity (Identity(..))
@@ -48,23 +49,26 @@ data VtyResult t = VtyResult
4849
-- on why each of these are necessary and how they can be fulfilled.
4950
type MonadVtyApp t m =
5051
( Reflex t
51-
, MonadHold t m
52-
, MonadHold t (Performable m)
53-
, MonadFix m
52+
, Adjustable t m
53+
, MonadCatch m
5454
, MonadFix (Performable m)
55-
, PrimMonad (HostFrame t)
56-
, ReflexHost t
55+
, MonadFix m
56+
, MonadHold t (Performable m)
57+
, MonadHold t m
5758
, MonadIO (HostFrame t)
58-
, Ref m ~ IORef
59-
, Ref (HostFrame t) ~ IORef
59+
, MonadIO (Performable m)
60+
, MonadIO m
61+
, MonadMask m
6062
, MonadRef (HostFrame t)
63+
, MonadThrow m
6164
, NotReady t m
62-
, TriggerEvent t m
63-
, PostBuild t m
6465
, PerformEvent t m
65-
, MonadIO m
66-
, MonadIO (Performable m)
67-
, Adjustable t m
66+
, PostBuild t m
67+
, PrimMonad (HostFrame t)
68+
, Ref (HostFrame t) ~ IORef
69+
, Ref m ~ IORef
70+
, ReflexHost t
71+
, TriggerEvent t m
6872
)
6973

7074
-- | A functional reactive vty application.

src/Reflex/Vty/Widget.hs

+16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Description: Basic set of widgets and building blocks for reflex-vty application
77
module Reflex.Vty.Widget where
88

99
import Control.Applicative (liftA2)
10+
import Control.Monad.Catch (MonadCatch, MonadThrow, MonadMask)
1011
import Control.Monad.Fix (MonadFix)
1112
import Control.Monad.IO.Class (MonadIO)
1213
import Control.Monad.Morph (MFunctor(..))
@@ -109,6 +110,9 @@ newtype Input t m a = Input
109110
, MonadFix
110111
, MonadIO
111112
, MonadRef
113+
, MonadCatch
114+
, MonadThrow
115+
, MonadMask
112116
)
113117

114118
instance (Adjustable t m, MonadHold t m, Reflex t) => Adjustable t (Input t m) where
@@ -336,6 +340,9 @@ newtype DisplayRegion t m a = DisplayRegion
336340
, MonadIO
337341
, MonadRef
338342
, MonadSample t
343+
, MonadCatch
344+
, MonadThrow
345+
, MonadMask
339346
)
340347

341348
instance (Monad m, Reflex t) => HasDisplayRegion t (DisplayRegion t m) where
@@ -401,6 +408,9 @@ newtype FocusReader t m a = FocusReader
401408
, MonadIO
402409
, MonadRef
403410
, MonadSample t
411+
, MonadCatch
412+
, MonadThrow
413+
, MonadMask
404414
)
405415

406416
instance (Monad m, Reflex t) => HasFocusReader t (FocusReader t m) where
@@ -466,6 +476,9 @@ newtype ImageWriter t m a = ImageWriter
466476
, PerformEvent t
467477
, PostBuild t
468478
, TriggerEvent t
479+
, MonadCatch
480+
, MonadThrow
481+
, MonadMask
469482
)
470483

471484
instance MonadTrans (ImageWriter t) where
@@ -536,6 +549,9 @@ newtype ThemeReader t m a = ThemeReader
536549
, MonadIO
537550
, MonadRef
538551
, MonadSample t
552+
, MonadCatch
553+
, MonadThrow
554+
, MonadMask
539555
)
540556

541557
instance (Monad m, Reflex t) => HasTheme t (ThemeReader t m) where

src/Reflex/Vty/Widget/Layout.hs

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Description: Monad transformer and tools for arranging widgets and building scre
77
module Reflex.Vty.Widget.Layout where
88

99
import Control.Applicative (liftA2)
10+
import Control.Monad.Catch (MonadCatch, MonadThrow, MonadMask)
1011
import Control.Monad.Morph
1112
import Control.Monad.NodeId (MonadNodeId(..), NodeId)
1213
import Control.Monad.Fix
@@ -111,6 +112,9 @@ newtype Focus t m a = Focus
111112
, PostBuild t
112113
, MonadNodeId
113114
, MonadIO
115+
, MonadCatch
116+
, MonadThrow
117+
, MonadMask
114118
)
115119

116120

@@ -395,6 +399,9 @@ newtype Layout t m a = Layout
395399
, PerformEvent t
396400
, PostBuild t
397401
, TriggerEvent t
402+
, MonadCatch
403+
, MonadThrow
404+
, MonadMask
398405
)
399406

400407
instance MonadTrans (Layout t) where

0 commit comments

Comments
 (0)