Skip to content

Commit

Permalink
Merge pull request #19 from purescript/ps-0.11
Browse files Browse the repository at this point in the history
Update for PureScript 0.11
  • Loading branch information
garyb committed Mar 26, 2017
2 parents 12e8fb2 + 008e59c commit 22ee549
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 61 deletions.
28 changes: 28 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,28 @@
{
"parserOptions": {
"ecmaVersion": 5
},
"extends": "eslint:recommended",
"env": {
"commonjs": true
},
"rules": {
"strict": [2, "global"],
"block-scoped-var": 2,
"consistent-return": 2,
"eqeqeq": [2, "smart"],
"guard-for-in": 2,
"no-caller": 2,
"no-extend-native": 2,
"no-loop-func": 2,
"no-new": 2,
"no-param-reassign": 2,
"no-return-assign": 2,
"no-unused-expressions": 2,
"no-use-before-define": 2,
"radix": [2, "always"],
"indent": [2, 2],
"quotes": [2, "double"],
"semi": [2, "always"]
}
}
3 changes: 1 addition & 2 deletions .gitignore
@@ -1,7 +1,6 @@
/.*
!/.gitignore
!/.jscsrc
!/.jshintrc
!/.eslintrc.json
!/.travis.yml
/bower_components/
/node_modules/
Expand Down
17 changes: 0 additions & 17 deletions .jscsrc

This file was deleted.

20 changes: 0 additions & 20 deletions .jshintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,7 +1,7 @@
language: node_js
dist: trusty
sudo: required
node_js: 6
node_js: stable
env:
- PATH=$HOME/purescript:$PATH
install:
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Expand Up @@ -21,6 +21,6 @@
"package.json"
],
"dependencies": {
"purescript-monoid": "^2.0.0"
"purescript-monoid": "^3.0.0"
}
}
11 changes: 5 additions & 6 deletions package.json
Expand Up @@ -2,13 +2,12 @@
"private": true,
"scripts": {
"clean": "rimraf output && rimraf .pulp-cache",
"build": "jshint src && jscs src && pulp build --censor-lib --strict"
"build": "eslint src && pulp build -- --censor-lib --strict"
},
"devDependencies": {
"jscs": "^2.8.0",
"jshint": "^2.9.1",
"pulp": "^9.0.1",
"purescript-psa": "^0.3.9",
"rimraf": "^2.5.0"
"eslint": "^3.17.1",
"pulp": "^10.0.4",
"purescript-psa": "^0.5.0-rc.1",
"rimraf": "^2.6.1"
}
}
32 changes: 18 additions & 14 deletions src/Data/Lazy.purs
Expand Up @@ -6,6 +6,7 @@ import Control.Comonad (class Comonad)
import Control.Extend (class Extend)
import Control.Lazy as CL

import Data.Functor.Invariant (class Invariant, imapF)
import Data.HeytingAlgebra (implies, ff, tt)
import Data.Monoid (class Monoid, mempty)

Expand All @@ -19,61 +20,64 @@ import Data.Monoid (class Monoid, mempty)
-- | type class instances.
-- |
-- | `Lazy` values can be evaluated by using the `force` function.
foreign import data Lazy :: * -> *
foreign import data Lazy :: Type -> Type

-- | Defer a computation, creating a `Lazy` value.
foreign import defer :: forall a. (Unit -> a) -> Lazy a

-- | Force evaluation of a `Lazy` value.
foreign import force :: forall a. Lazy a -> a

instance semiringLazy :: (Semiring a) => Semiring (Lazy a) where
instance semiringLazy :: Semiring a => Semiring (Lazy a) where
add a b = defer \_ -> force a + force b
zero = defer \_ -> zero
mul a b = defer \_ -> force a * force b
one = defer \_ -> one

instance ringLazy :: (Ring a) => Ring (Lazy a) where
instance ringLazy :: Ring a => Ring (Lazy a) where
sub a b = defer \_ -> force a - force b

instance commutativeRingLazy :: (CommutativeRing a) => CommutativeRing (Lazy a)
instance commutativeRingLazy :: CommutativeRing a => CommutativeRing (Lazy a)

instance euclideanRingLazy :: (EuclideanRing a) => EuclideanRing (Lazy a) where
instance euclideanRingLazy :: EuclideanRing a => EuclideanRing (Lazy a) where
degree = degree <<< force
div a b = defer \_ -> force a / force b
mod a b = defer \_ -> force a `mod` force b

instance fieldLazy :: (Field a) => Field (Lazy a)
instance fieldLazy :: Field a => Field (Lazy a)

instance eqLazy :: (Eq a) => Eq (Lazy a) where
instance eqLazy :: Eq a => Eq (Lazy a) where
eq x y = (force x) == (force y)

instance ordLazy :: (Ord a) => Ord (Lazy a) where
instance ordLazy :: Ord a => Ord (Lazy a) where
compare x y = compare (force x) (force y)

instance boundedLazy :: (Bounded a) => Bounded (Lazy a) where
instance boundedLazy :: Bounded a => Bounded (Lazy a) where
top = defer \_ -> top
bottom = defer \_ -> bottom

instance semigroupLazy :: (Semigroup a) => Semigroup (Lazy a) where
instance semigroupLazy :: Semigroup a => Semigroup (Lazy a) where
append a b = defer \_ -> force a <> force b

instance monoidLazy :: (Monoid a) => Monoid (Lazy a) where
instance monoidLazy :: Monoid a => Monoid (Lazy a) where
mempty = defer \_ -> mempty

instance heytingAlgebraLazy :: (HeytingAlgebra a) => HeytingAlgebra (Lazy a) where
instance heytingAlgebraLazy :: HeytingAlgebra a => HeytingAlgebra (Lazy a) where
ff = defer \_ -> ff
tt = defer \_ -> tt
implies a b = implies <$> a <*> b
conj a b = conj <$> a <*> b
disj a b = disj <$> a <*> b
not a = not <$> a

instance booleanAlgebraLazy :: (BooleanAlgebra a) => BooleanAlgebra (Lazy a)
instance booleanAlgebraLazy :: BooleanAlgebra a => BooleanAlgebra (Lazy a)

instance functorLazy :: Functor Lazy where
map f l = defer \_ -> f (force l)

instance invariantLazy :: Invariant Lazy where
imap = imapF

instance applyLazy :: Apply Lazy where
apply f x = defer \_ -> force f (force x)

Expand All @@ -91,7 +95,7 @@ instance extendLazy :: Extend Lazy where
instance comonadLazy :: Comonad Lazy where
extract = force

instance showLazy :: (Show a) => Show (Lazy a) where
instance showLazy :: Show a => Show (Lazy a) where
show x = "(defer \\_ -> " <> show (force x) <> ")"

instance lazyLazy :: CL.Lazy (Lazy a) where
Expand Down

0 comments on commit 22ee549

Please sign in to comment.