Skip to content

Commit

Permalink
Merge pull request #2 from eskimor/psc-0.9.1
Browse files Browse the repository at this point in the history
Made it work for psc 0.9.1 including test suite
  • Loading branch information
zudov authored Jul 6, 2016
2 parents 1a830d7 + 5270cf8 commit 21083aa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
],
"keywords": [ "purescript" ],
"dependencies": {
"purescript-eff": "^0.1.2",
"purescript-contravariant": "^0.2.3",
"purescript-invariant": "^0.3.0"
"purescript-eff": "^1.0.0",
"purescript-contravariant": "^1.0.0",
"purescript-invariant": "^1.0.0"
},
"devDependencies": {
"purescript-console": "^0.1.1"
"purescript-console": "^1.0.0"
}
}
38 changes: 18 additions & 20 deletions src/Control/Monad/Eff/Var.purs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
-- | ```

module Control.Monad.Eff.Var
( Gettable
( class Gettable
, get
, Settable
, class Settable
, set
, ($=)
, Updatable
, class Updatable
, update
, ($~)
, Var()
Expand All @@ -44,13 +44,16 @@ module Control.Monad.Eff.Var

import Prelude

import Control.Monad.Eff
import Control.Monad.Eff (Eff)
import Data.Decidable (class Decidable)
import Data.Decide (class Decide)
import Data.Divide (class Divide)
import Data.Divisible (class Divisible)
import Data.Tuple (Tuple(..))
import Data.Either (either)
import Data.Functor.Contravariant (class Contravariant, (>$<))
import Data.Functor.Invariant (class Invariant)

import Data.Tuple
import Data.Either
import Data.Functor.Contravariant
import Data.Functor.Contravariant.Divisible
import Data.Functor.Invariant

-- | Typeclass for vars that can be read.
class Gettable (eff :: # !) (var :: * -> *) (a :: *) where
Expand All @@ -61,20 +64,14 @@ class Settable (eff :: # !) (var :: * -> *) (a :: *) where
set :: var a -> a -> Eff eff Unit

-- | Alias for `set`.
infixr 2 $=
($=) :: forall eff var a. (Settable eff var a)
=> var a -> a -> Eff eff Unit
($=) = set
infixr 2 set as $=

-- | Typeclass for vars that can be updated.
class Updatable (eff :: # !) (var :: * -> *) (a :: *) where
update :: var a -> (a -> a) -> Eff eff Unit

-- | Alias for `get`
infixr 2 $~
($~) :: forall eff var a. (Updatable eff var a)
=> var a -> (a -> a) -> Eff eff Unit
($~) = update
infixr 2 update as $~

-- | Read/Write var which holds a value of type `a` and produces effects `eff`
-- | when read or written.
Expand Down Expand Up @@ -138,10 +135,11 @@ instance divideSettableVar :: Divide (SettableVar eff) where
setc c

instance divisibleSettableVar :: Divisible (SettableVar eff) where
conquer = SettableVar \_ -> return unit
conquer = SettableVar \_ -> pure unit

instance decideSettableVar :: Decide (SettableVar eff) where
decide f (SettableVar setb) (SettableVar setc) = SettableVar (either setb setc <<< f)
choose f (SettableVar setb) (SettableVar setc) = SettableVar (either setb setc <<< f)

instance decidableSettableVar :: Decidable (SettableVar eff) where
lose = SettableVar
-- lose :: forall a. (a -> Void) -> f a
lose f = SettableVar (absurd <<< f)
6 changes: 4 additions & 2 deletions test/Main.purs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Test.Main where

import Prelude

import Control.Monad.Eff
import Control.Monad.Eff.Var
import Control.Monad.Eff.Console
Expand All @@ -18,5 +17,8 @@ main = do
get counter >>= print -- => 0
counter $= 2 -- set counter to 2
get counter >>= print -- => 2
counter $~ (* 5) -- multiply counter by 5
counter $~ (_ * 5) -- multiply counter by 5
get counter >>= print -- => 10

print :: forall eff a. Show a => a -> Eff (console :: CONSOLE | eff) Unit
print = log <<< show

0 comments on commit 21083aa

Please sign in to comment.